Class: VagrantPlugins::Cloudcenter::Command::Root
- Inherits:
-
Object
- Object
- VagrantPlugins::Cloudcenter::Command::Root
- Defined in:
- lib/vagrant-cloudcenter/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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vagrant-cloudcenter/command/root.rb', line 16 def initialize(argv, env) @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv) @subcommands = Vagrant::Registry.new @subcommands.register(:catalog) do require File.("../catalog", __FILE__) Catalog end @subcommands.register(:app) do require File.("../app", __FILE__) App end @subcommands.register(:jobs) do require File.("../jobs", __FILE__) Jobs end @subcommands.register(:init) do require File.("../init", __FILE__) Init end @subcommands.register(:sync) do require File.("../sync", __FILE__) Sync end super(argv, env) end |
Class Method Details
.synopsis ⇒ Object
12 13 14 |
# File 'lib/vagrant-cloudcenter/command/root.rb', line 12 def self.synopsis "deploy a new environment using Cisco CloudCenter" end |
Instance Method Details
#execute ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vagrant-cloudcenter/command/root.rb', line 44 def execute if @main_args.include?("-h") || @main_args.include?("--help") # Print the help for all the commands. 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}") # Initialize and execute the command class command_class.new(@sub_args, @env).execute end |
#help ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/vagrant-cloudcenter/command/root.rb', line 58 def help opts = OptionParser.new do |opts| opts. = "Usage: vagrant cloudcenter <subcommand> [<args>]" opts.separator "" opts.separator "Available subcommands:\n" # Add the available subcommands as separators in order to print them # out as well. keys = [] commands = {} longest = 0 @subcommands.each do |key, data| keys << key commands[key] = data.synopsis longest = key.length if key.length > longest end keys.sort.each do |key| key.to_sym synopsis = commands[key].to_str command = key.to_s opts.separator " #{command.ljust(longest+2)} #{synopsis}" end opts.separator "" opts.separator "For help on any individual subcommand run `vagrant cloudcenter <subcommand> -h`" end @env.ui.info(opts.help, :prefix => false) end |