Class: Nugrant::Vagrant::V2::Command::Root
- Inherits:
-
Object
- Object
- Nugrant::Vagrant::V2::Command::Root
- Defined in:
- lib/nugrant/vagrant/v2/command/root.rb
Instance Method Summary collapse
- #create_parser ⇒ Object
- #execute ⇒ Object
- #help(parser) ⇒ Object
-
#initialize(arguments, environment) ⇒ Root
constructor
A new instance of Root.
- #version ⇒ Object
Constructor Details
#initialize(arguments, environment) ⇒ Root
Returns a new instance of Root.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/nugrant/vagrant/v2/command/root.rb', line 11 def initialize(arguments, environment) super(arguments, environment) @arguments, @subcommand, @subarguments = split_main_and_subcommand(arguments) # Change super class available arguments to main ones only @argv = @arguments @subcommands = ::Vagrant::Registry.new() @subcommands.register(:env) do Command::Env end @subcommands.register(:parameters) do Command::Parameters end @show_help = false @show_version = false end |
Instance Method Details
#create_parser ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/nugrant/vagrant/v2/command/root.rb', line 32 def create_parser() return OptionParser.new do |parser| parser. = "Usage: vagrant user [-h] [-v] <command> [<args>]" parser.separator "" parser.on("-h", "--help", "Print this help") do @show_help = true end parser.on("-v", "--version", "Print plugin version and exit.") do @show_version = true end parser.separator "" parser.separator "Available subcommands:" keys = [] @subcommands.each { |key, value| keys << key.to_s } keys.sort.each do |key| parser.separator " #{key}" end parser.separator "" parser.separator "For help on any individual command run `vagrant user COMMAND -h`" end end |
#execute ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nugrant/vagrant/v2/command/root.rb', line 60 def execute parser = create_parser() arguments = (parser) return version() if @show_version return help(parser) if @show_help command_class = @subcommands.get(@subcommand.to_sym) if @subcommand return help(parser) if !command_class || !@subcommand @logger.debug("Invoking nugrant command class: #{command_class} #{@subarguments.inspect}") command_class.new(@subarguments, @env).execute end |
#help(parser) ⇒ Object
75 76 77 |
# File 'lib/nugrant/vagrant/v2/command/root.rb', line 75 def help(parser) @env.ui.info(parser.help, :prefix => false) end |