Class: Brainstem::CLI::AbstractCommand
- Inherits:
-
Object
- Object
- Brainstem::CLI::AbstractCommand
- Defined in:
- lib/brainstem/cli/abstract_command.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Object
Storage for passed, unparsed args.
-
#options ⇒ Object
Storage for given options.
Class Method Summary collapse
-
.call(args = []) ⇒ Brainstem::CLI::AbstractCommand
Convenience method for instantiating the command and calling it.
Instance Method Summary collapse
-
#call ⇒ Object
Kicks off execution of app-level code.
-
#default_options ⇒ Object
Returns the hash of default options used as a base into which cli args are merged.
-
#extract_options! ⇒ Hash
Extracts command-line options for this specific command based on the
OptionParser
specified inself.option_parser
. -
#initialize(args = []) ⇒ AbstractCommand
constructor
Returns a new instance of the command with options set.
-
#option_parser ⇒ OptionParser
An
OptionParser
instance that specifies how options should be extracted specific to this command.
Constructor Details
#initialize(args = []) ⇒ AbstractCommand
Returns a new instance of the command with options set.
31 32 33 34 35 |
# File 'lib/brainstem/cli/abstract_command.rb', line 31 def initialize(args = []) self.args = args self. = end |
Instance Attribute Details
#args ⇒ Object
Storage for passed, unparsed args.
62 63 64 |
# File 'lib/brainstem/cli/abstract_command.rb', line 62 def args @args end |
#options ⇒ Object
Storage for given options.
57 58 59 |
# File 'lib/brainstem/cli/abstract_command.rb', line 57 def @options end |
Class Method Details
.call(args = []) ⇒ Brainstem::CLI::AbstractCommand
Convenience method for instantiating the command and calling it.
22 23 24 25 26 |
# File 'lib/brainstem/cli/abstract_command.rb', line 22 def self.call(args = []) instance = new(args) instance.call instance end |
Instance Method Details
#call ⇒ Object
Kicks off execution of app-level code. Has available to it options
, which contains the options extracted from the command line.
49 50 51 52 |
# File 'lib/brainstem/cli/abstract_command.rb', line 49 def call raise NotImplementedError, "Override #call and implement your application logic." end |
#default_options ⇒ Object
Returns the hash of default options used as a base into which cli args are merged.
41 42 43 |
# File 'lib/brainstem/cli/abstract_command.rb', line 41 def {} end |
#extract_options! ⇒ Hash
Extracts command-line options for this specific command based on the OptionParser
specified in self.option_parser
.
70 71 72 |
# File 'lib/brainstem/cli/abstract_command.rb', line 70 def option_parser.order!(args) end |
#option_parser ⇒ OptionParser
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.
84 85 86 87 |
# File 'lib/brainstem/cli/abstract_command.rb', line 84 def option_parser raise NotImplementedError, "Must return an instance of OptionParser." end |