class SANStore::CLI::Base
@author Denis Defreyne @author David Love
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 {Base#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.
Public Class Methods
Instantiates the sub-commands by creating a single reference to each known sub-command.
@note 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!
Cri::Base::new
# 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
Public Instance Methods
Returns the list of global option definitionss.
# 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
Process the global options, and set/change the application state from them
# 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