Class: Vagrant::LXC::Command::Root
- Inherits:
-
Object
- Object
- Vagrant::LXC::Command::Root
- Defined in:
- lib/vagrant-lxc/command/root.rb
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
- #help ⇒ Object
-
#initialize(argv, env) ⇒ Root
constructor
A new instance of Root.
Constructor Details
#initialize(argv, env) ⇒ Root
Returns a new instance of Root.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vagrant-lxc/command/root.rb', line 9 def initialize(argv, env) @args, @sub_command, @sub_args = split_main_and_subcommand(argv) @subcommands = Vagrant::Registry.new.tap do |registry| registry.register(:sudoers) do require_relative 'sudoers' Sudoers end end super(argv, env) end |
Class Method Details
.synopsis ⇒ Object
5 6 7 |
# File 'lib/vagrant-lxc/command/root.rb', line 5 def self.synopsis 'vagrant-lxc specific commands' end |
Instance Method Details
#execute ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-lxc/command/root.rb', line 20 def execute # Print the help return help if @args.include?("-h") || @args.include?("--help") klazz = @subcommands.get(@sub_command.to_sym) if @sub_command return help unless klazz @logger.debug("Executing command: #{klazz} #{@sub_args.inspect}") # Initialize and execute the command class klazz.new(@sub_args, @env).execute end |
#help ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vagrant-lxc/command/root.rb', line 33 def help opts = OptionParser.new do |opts| opts. = "Usage: vagrant lxc <subcommand> [<args>]" opts.separator "" opts.separator "Available subcommands:" # REFACTOR Use @subcommands.keys.sort # https://github.com/mitchellh/vagrant/commit/4194da19c60956f6e59239c0145f772be257e79d keys = [] @subcommands.each { |key, value| keys << key } keys.sort.each do |key| opts.separator " #{key}" end opts.separator "" opts.separator "For help on any individual subcommand run `vagrant lxc <subcommand> -h`" end @env.ui.info(opts.help, :prefix => false) end |