Skip to content

Commit

Permalink
Make commands API more consistent with both single and group commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Sep 21, 2010
1 parent 4a25aca commit 5316a52
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 35 deletions.
6 changes: 2 additions & 4 deletions lib/vagrant/command/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ class Base < Thor::Group
# given name. The name will be used for accessing it from the CLI,
# so if you name it "lamp", then the command to invoke this
# will be `vagrant lamp`.
#
# The description added to the class via the `desc` method will be
# used as a description for the command.
def self.register(usage, opts=nil)
def self.register(usage, description, opts=nil)
desc description
CLI.register(self, extract_name_from_usage(usage), usage, desc, opts)
end

Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/destroy.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Vagrant
module Command
class DestroyCommand < NamedBase
desc "Destroy the environment, deleting the created virtual machines"
register "destroy"
register "destroy", "Destroy the environment, deleting the created virtual machines"

def execute
target_vms.each do |vm|
Expand Down
3 changes: 0 additions & 3 deletions lib/vagrant/command/group_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class GroupBase < Thor
# usage. The usage will be used for accessing it from the CLI,
# so if you give it a usage of `lamp [subcommand]`, then the command
# to invoke this will be `vagrant lamp` (with a subcommand).
#
# Additionally, unlike {Base}, a description must be specified to
# this register command, since there is no class-wide description.
def self.register(usage, description, opts=nil)
CLI.register(self, Base.extract_name_from_usage(usage), usage, description, opts)
end
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/halt.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Vagrant
module Command
class HaltCommand < NamedBase
desc "Halt the running VMs in the environment"
class_option :force, :type => :boolean, :default => false, :aliases => "-f"
register "halt"
register "halt", "Halt the running VMs in the environment"

def execute
target_vms.each do |vm|
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/init.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module Vagrant
module Command
class InitCommand < Base
desc "Initializes the current folder for Vagrant usage"
argument :box_name, :type => :string, :optional => true, :default => "base"
argument :box_url, :type => :string, :optional => true
source_root File.expand_path("templates/commands/init", Vagrant.source_root)
register "init [box_name] [box_url]"
register "init [box_name] [box_url]", "Initializes the current folder for Vagrant usage"

def execute
template "Vagrantfile.erb", "Vagrantfile"
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/package.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module Vagrant
module Command
class PackageCommand < NamedBase
desc "Package a Vagrant environment for distribution"
class_option :base, :type => :string, :default => nil
class_option :output, :type => :string, :default => nil
class_option :include, :type => :array, :default => nil
class_option :vagrantfile, :type => :string, :default => nil
register "package"
register "package", "Package a Vagrant environment for distribution"

def execute
return package_base if options[:base]
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/provision.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Vagrant
module Command
class ProvisionCommand < NamedBase
desc "Rerun the provisioning scripts on a running VM"
register "provision"
register "provision", "Rerun the provisioning scripts on a running VM"

def execute
target_vms.each do |vm|
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/reload.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Vagrant
module Command
class ReloadCommand < NamedBase
desc "Reload the environment, halting it then restarting it."
register "reload"
register "reload", "Reload the environment, halting it then restarting it."

def execute
target_vms.each do |vm|
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/resume.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Vagrant
module Command
class ResumeCommand < NamedBase
desc "Resume a suspended Vagrant environment."
register "resume"
register "resume", "Resume a suspended Vagrant environment."

def execute
target_vms.each do |vm|
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/ssh.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Vagrant
module Command
class SSHCommand < NamedBase
desc "SSH into the currently running Vagrant environment."
class_option :execute, :type => :string, :default => false, :aliases => "-e"
register "ssh"
register "ssh", "SSH into the currently running Vagrant environment."

def execute
if options[:execute]
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/ssh_config.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Vagrant
module Command
class SSHConfigCommand < NamedBase
desc "outputs .ssh/config valid syntax for connecting to this environment via ssh"
class_option :host, :type => :string, :default => nil, :aliases => "-h"
register "ssh_config"
register "ssh_config", "outputs .ssh/config valid syntax for connecting to this environment via ssh"

def execute
raise MultiVMTargetRequired.new(:command => "ssh_config") if target_vms.length > 1
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/status.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Vagrant
module Command
class StatusCommand < Base
desc "Shows the status of the current Vagrant environment."
argument :name, :type => :string, :optional => true
register "status"
register "status", "Shows the status of the current Vagrant environment."

def route
state = nil
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/suspend.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Vagrant
module Command
class SuspendCommand < NamedBase
desc "Suspend a running Vagrant environment."
register "suspend"
register "suspend", "Suspend a running Vagrant environment."

def execute
target_vms.each do |vm|
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/up.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Vagrant
module Command
class UpCommand < NamedBase
desc "Creates the Vagrant environment"
class_option :provision, :type => :boolean, :default => true
register "up"
register "up", "Creates the Vagrant environment"

def execute
# TODO: Make the options[:provision] actually mean something
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/upgrade_to_060.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
module Vagrant
module Command
class UpgradeTo060Command < Base
desc "Upgrade pre-0.6.0 environment to 0.6.0"
register "upgrade_to_060", :hide => true
register "upgrade_to_060", "Upgrade pre-0.6.0 environment to 0.6.0", :hide => true

def execute
@env.ui.warn "vagrant.commands.upgrade_to_060.info", :_prefix => false
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant/command/version.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Vagrant
module Command
class VersionCommand < Base
desc "Prints the Vagrant version information"
register "version", :alias => %w(-v --version)
register "version", "Prints the Vagrant version information", :alias => %w(-v --version)

def version
env.ui.info("vagrant.commands.version.output",
Expand Down

0 comments on commit 5316a52

Please sign in to comment.