Class: VagrantPlugins::Solidus::Command
- Inherits:
-
Object
- Object
- VagrantPlugins::Solidus::Command
show all
- Defined in:
- lib/vagrant-solidus/command.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(argv, env) ⇒ Command
Returns a new instance of Command.
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/vagrant-solidus/command.rb', line 16
def initialize(argv, env)
super
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
@subcommands = Vagrant::Registry.new
subcommands.each do |subcommand|
@subcommands.register(subcommand.to_sym) do
require_relative "#{command}/#{subcommand}"
eval((self.class.to_s.split('::')[0...-1] + [subcommand.capitalize]).join('::'))
end
end
end
|
Class Method Details
.synopsis ⇒ Object
4
5
6
|
# File 'lib/vagrant-solidus/command.rb', line 4
def self.synopsis
'command description'
end
|
Instance Method Details
#command ⇒ Object
8
9
10
|
# File 'lib/vagrant-solidus/command.rb', line 8
def command
'the-command'
end
|
#execute ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/vagrant-solidus/command.rb', line 30
def execute
if @main_args.include?("-h") || @main_args.include?("--help")
return help
end
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
return help if !command_class || !@sub_command
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
command_class.new(@sub_args, @env).execute
end
|
#help ⇒ Object
Prints the help out for this command
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/vagrant-solidus/command.rb', line 47
def help
opts = OptionParser.new do |opts|
opts.banner = "Usage: vagrant #{command} SUBCOMMAND [OPTIONS]"
opts.separator ""
opts.separator "Available subcommands:"
keys = []
@subcommands.each { |key, value| keys << key.to_s }
keys.sort.each do |key|
opts.separator " #{key}"
end
opts.separator ""
opts.separator "For help on any individual subcommand run `vagrant #{command} SUBCOMMAND -h`"
end
@env.ui.info(opts.help, :prefix => false)
end
|
#subcommands ⇒ Object
12
13
14
|
# File 'lib/vagrant-solidus/command.rb', line 12
def subcommands
%w[the subcommands]
end
|