class Brainstem::CLI::AbstractCommand
Attributes
Storage for passed, unparsed args.
Storage for given options.
Public Class Methods
Convenience method for instantiating the command and calling it.
@return [Brainstem::CLI::AbstractCommand] the instance
# File lib/brainstem/cli/abstract_command.rb, line 22 def self.call(args = []) instance = new(args) instance.call instance end
Returns a new instance of the command with options set.
# File lib/brainstem/cli/abstract_command.rb, line 31 def initialize(args = []) self.args = args self.options = default_options extract_options! end
Public Instance Methods
Kicks off execution of app-level code. Has available to it options
, which contains the options extracted from the command line.
# File lib/brainstem/cli/abstract_command.rb, line 49 def call raise NotImplementedError, "Override #call and implement your application logic." end
Returns the hash of default options used as a base into which cli args are merged.
# File lib/brainstem/cli/abstract_command.rb, line 41 def default_options {} end
Extracts command-line options for this specific command based on the OptionParser
specified in self.option_parser
.
@return [Hash] the extracted command-line options
# File lib/brainstem/cli/abstract_command.rb, line 70 def extract_options! option_parser.order!(args) end
An OptionParser
instance that specifies how options should be extracted specific to this command.
Available to this method is the options
method, which is the primary method of communicating options to the call
method.
@return [OptionParser] an instance of OptionParser @see ruby-doc.org/stdlib-2.2.2/libdoc/optparse/rdoc/OptionParser.html
# File lib/brainstem/cli/abstract_command.rb, line 84 def option_parser raise NotImplementedError, "Must return an instance of OptionParser." end