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.
32 33 34 35 36 |
# File 'lib/brainstem/cli/abstract_command.rb', line 32 def initialize(args = []) self.args = args self. = end |
Instance Attribute Details
#args ⇒ Object
Storage for passed, unparsed args.
67 68 69 |
# File 'lib/brainstem/cli/abstract_command.rb', line 67 def args @args end |
#options ⇒ Object
Storage for given options.
61 62 63 |
# File 'lib/brainstem/cli/abstract_command.rb', line 61 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.
52 53 54 55 |
# File 'lib/brainstem/cli/abstract_command.rb', line 52 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.
43 44 45 |
# File 'lib/brainstem/cli/abstract_command.rb', line 43 def {} end |
#extract_options! ⇒ Hash
Extracts command-line options for this specific command based on the OptionParser
specified in self.option_parser
.
76 77 78 |
# File 'lib/brainstem/cli/abstract_command.rb', line 76 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.
91 92 93 94 |
# File 'lib/brainstem/cli/abstract_command.rb', line 91 def option_parser raise NotImplementedError, "Must return an instance of OptionParser." end |