Class: SANStore::CLI::Base
- Defined in:
- lib/SANStore/cli/base.rb
Overview
Details the global options applicable to all commands, and the code necessary to process those options. Each sub-command also needs to be registered with this class for it to work: strange things will happen if the sub-command is not set-up here!
When creating a new sub-command, the constructor for that sub-command needs to be added to the #initialize function of this class as well. Be sure to also add the path to the file where the sub-command is defined to the file lib/SANStore/cli/commands.rb
, otherwise you will get warnings of unknown classes.
Instance Attribute Summary
Attributes inherited from Cri::Base
Instance Method Summary collapse
-
#global_option_definitions ⇒ Object
Returns the list of global option definitionss.
-
#handle_option(option) ⇒ Object
Process the global options, and set/change the application state from them.
-
#initialize ⇒ Base
constructor
Instantiates the sub-commands by creating a single reference to each known sub-command.
Methods inherited from Cri::Base
#add_command, #command_named, #run, #show_help
Constructor Details
#initialize ⇒ Base
This means that if your sub-command is not in this constructor it *will not* be found, and *will not* appear as a valid sub-command. If something is missing from the ‘help’ command, check this method!
Instantiates the sub-commands by creating a single reference to each known sub-command.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/SANStore/cli/base.rb', line 46 def initialize super('SANStore') # Add help command self.help_command = SANStore::CLI::Commands::Help.new add_command(self.help_command) # Add other commands add_command(SANStore::CLI::Commands::DeleteVol.new) add_command(SANStore::CLI::Commands::ListVols.new) add_command(SANStore::CLI::Commands::NewVol.new) end |
Instance Method Details
#global_option_definitions ⇒ Object
Returns the list of global option definitionss.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/SANStore/cli/base.rb', line 60 def global_option_definitions [ { :long => 'help', :short => 'h', :argument => :forbidden, :desc => 'show this help message and quit' }, { :long => 'no-color', :short => 'C', :argument => :forbidden, :desc => 'disable color' }, { :long => 'version', :short => 'v', :argument => :forbidden, :desc => 'show version information and quit' }, { :long => 'verbose', :short => 'V', :argument => :forbidden, :desc => 'make store command output more detailed' } ] end |
#handle_option(option) ⇒ Object
Process the global options, and set/change the application state from them
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/SANStore/cli/base.rb', line 82 def handle_option(option) # Handle version option if option == :version puts "SANStore Bootstrap Client #{SANStore::VERSION} (c) 2011 David Love." puts "Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) running on #{RUBY_PLATFORM}" exit 0 # Handle verbose option elsif option == :verbose SANStore::CLI::Logger.instance.level = :low # Handle no-color option elsif option == :'no-color' SANStore::CLI::Logger.instance.color = false # Handle help option elsif option == :help show_help exit 0 end end |