Commenting on the Vagrant::Command class
This commit is contained in:
parent
5c3171a8f9
commit
83da66ee91
|
@ -6,6 +6,8 @@ module Vagrant
|
||||||
attr_reader :env
|
attr_reader :env
|
||||||
|
|
||||||
class <<self
|
class <<self
|
||||||
|
# Executes a given subcommand within the current environment (from the
|
||||||
|
# current working directory).
|
||||||
def execute(*args)
|
def execute(*args)
|
||||||
env = Environment.load!
|
env = Environment.load!
|
||||||
env.commands.subcommand(*args)
|
env.commands.subcommand(*args)
|
||||||
|
@ -16,12 +18,15 @@ module Vagrant
|
||||||
@env = env
|
@env = env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Execute a subcommand with the given name and args. This method properly
|
||||||
|
# finds the subcommand, instantiates it, and executes.
|
||||||
def subcommand(name, *args)
|
def subcommand(name, *args)
|
||||||
command_klass = Commands.const_get(camelize(name))
|
command_klass = Commands.const_get(camelize(name))
|
||||||
command = command_klass.new(env)
|
command = command_klass.new(env)
|
||||||
command.execute(args)
|
command.execute(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Camel-case a string.
|
||||||
def camelize(string)
|
def camelize(string)
|
||||||
parts = string.to_s.split(/[^a-z0-9]/).collect do |part|
|
parts = string.to_s.split(/[^a-z0-9]/).collect do |part|
|
||||||
part.capitalize
|
part.capitalize
|
||||||
|
|
Loading…
Reference in New Issue