diff --git a/plugins/commands/snapshot/command/pop.rb b/plugins/commands/snapshot/command/pop.rb index a10d57227..3f11dc24a 100644 --- a/plugins/commands/snapshot/command/pop.rb +++ b/plugins/commands/snapshot/command/pop.rb @@ -1,6 +1,10 @@ require 'json' require 'optparse' +require 'vagrant' + +require Vagrant.source_root.join("plugins/commands/up/start_mixins") + require_relative "push_shared" module VagrantPlugins @@ -8,16 +12,19 @@ module VagrantPlugins module Command class Pop < Vagrant.plugin("2", :command) include PushShared + include VagrantPlugins::CommandUp::StartMixins def execute options = {} + options[:snapshot_delete] = true opts = OptionParser.new do |o| o.banner = "Usage: vagrant snapshot pop [options] [vm-name]" o.separator "" + build_start_options(o, options) o.separator "Restore state that was pushed with `vagrant snapshot push`." o.on("--no-delete", "Don't delete the snapshot after the restore") do - options[:no_delete] = true + options[:snapshot_delete] = false end end @@ -25,6 +32,9 @@ module VagrantPlugins argv = parse_options(opts) return if !argv + # Validate the provisioners + validate_provisioner_flags!(options, argv) + return shared_exec(argv, method(:pop), options) end end diff --git a/plugins/commands/snapshot/command/push_shared.rb b/plugins/commands/snapshot/command/push_shared.rb index 2942b6f23..d9691da34 100644 --- a/plugins/commands/snapshot/command/push_shared.rb +++ b/plugins/commands/snapshot/command/push_shared.rb @@ -45,16 +45,9 @@ module VagrantPlugins return end - snapshot_delete = true - if opts.key?(:no_delete) - snapshot_delete = false - end - # Restore the snapshot and tell the provider to delete it, if required - machine.action( - :snapshot_restore, - snapshot_name: name, - snapshot_delete: snapshot_delete) + opts[:snapshot_name] = name + machine.action(:snapshot_restore, opts) end end end diff --git a/plugins/commands/snapshot/command/restore.rb b/plugins/commands/snapshot/command/restore.rb index 930a811f4..18ca0fe04 100644 --- a/plugins/commands/snapshot/command/restore.rb +++ b/plugins/commands/snapshot/command/restore.rb @@ -1,15 +1,23 @@ require 'optparse' +require 'vagrant' + +require Vagrant.source_root.join("plugins/commands/up/start_mixins") + module VagrantPlugins module CommandSnapshot module Command class Restore < Vagrant.plugin("2", :command) + + include VagrantPlugins::CommandUp::StartMixins + def execute options = {} opts = OptionParser.new do |o| o.banner = "Usage: vagrant snapshot restore [options] [vm-name] " o.separator "" + build_start_options(o, options) o.separator "Restore a snapshot taken previously with snapshot save." end @@ -21,9 +29,14 @@ module VagrantPlugins help: opts.help.chomp end + # Validate the provisioners + validate_provisioner_flags!(options, argv) + name = argv.pop + options[:snapshot_name] = name + with_target_vms(argv) do |vm| - vm.action(:snapshot_restore, snapshot_name: name) + vm.action(:snapshot_restore, options) end # Success, exit status 0