From bdc39aa2e0b7777f7bbb734ac2923f13c9855723 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 17 Dec 2011 12:04:35 -0800 Subject: [PATCH] Suspend command --- lib/vagrant.rb | 1 + lib/vagrant/command.rb | 1 + lib/vagrant/command/suspend.rb | 23 ++++++++++++++++++----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 37423c71b..a7a3f9443 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -99,6 +99,7 @@ Vagrant.commands.register(:halt) { Vagrant::Command::Halt } Vagrant.commands.register(:provision) { Vagrant::Command::Provision } Vagrant.commands.register(:reload) { Vagrant::Command::Reload } Vagrant.commands.register(:resume) { Vagrant::Command::Resume } +Vagrant.commands.register(:suspend) { Vagrant::Command::Suspend } Vagrant.commands.register(:up) { Vagrant::Command::Up } # Register the built-in config keys diff --git a/lib/vagrant/command.rb b/lib/vagrant/command.rb index 8e4917bf2..99b7ba828 100644 --- a/lib/vagrant/command.rb +++ b/lib/vagrant/command.rb @@ -7,6 +7,7 @@ module Vagrant autoload :Provision, 'vagrant/command/provision' autoload :Reload, 'vagrant/command/reload' autoload :Resume, 'vagrant/command/resume' + autoload :Suspend, 'vagrant/command/suspend' autoload :Up, 'vagrant/command/up' end end diff --git a/lib/vagrant/command/suspend.rb b/lib/vagrant/command/suspend.rb index a590d16cd..21054b990 100644 --- a/lib/vagrant/command/suspend.rb +++ b/lib/vagrant/command/suspend.rb @@ -1,14 +1,27 @@ +require 'optparse' + module Vagrant module Command - class SuspendCommand < NamedBase - register "suspend", "Suspend a running Vagrant environment." - + class Suspend < Base def execute - target_vms.each do |vm| + options = {} + + opts = OptionParser.new do |opts| + opts.banner = "Usage: vagrant suspend [vm-name]" + end + + # Parse the options + argv = parse_options(opts) + return if !argv + + @logger.debug("'suspend' each target VM...") + with_target_vms(argv[0]) do |vm| if vm.created? + @logger.info("Suspending: #{vm.name}") vm.suspend else - vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created") + @logger.info("Not created: #{vm.name}. Not suspending.") + vm.ui.info I18n.t("vagrant.commands.common.vm_not_created") end end end