Class: Brainstem::Cli
- Inherits:
-
Object
- Object
- Brainstem::Cli
- Includes:
- Brainstem::Concerns::Optional
- Defined in:
- lib/brainstem/cli.rb
Constant Summary collapse
- EXECUTABLE_NAME =
'brainstem'
Instance Attribute Summary collapse
-
#_args ⇒ Object
Holds a copy of the initial given args for debugging purposes.
-
#requested_command ⇒ Object
Storage for the extracted command.
Class Method Summary collapse
-
.call(args, options = {}) ⇒ Brainstem::Cli
Convenience for instantiating and calling the Cli object.
Instance Method Summary collapse
-
#call ⇒ Brainstem::Cli
Routes to an application endpoint depending on given options.
-
#initialize(args, options = {}) ⇒ Cli
constructor
Creates a new instance of the Cli to respond to user input.
Constructor Details
#initialize(args, options = {}) ⇒ Cli
Creates a new instance of the Cli to respond to user input.
Input is expected to be the name of the subcommand, followed by any additional arguments.
29 30 31 32 33 34 |
# File 'lib/brainstem/cli.rb', line 29 def initialize(args, = {}) super self._args = args.dup.freeze self.requested_command = args.shift end |
Instance Attribute Details
#_args ⇒ Object
Holds a copy of the initial given args for debugging purposes.
54 55 56 |
# File 'lib/brainstem/cli.rb', line 54 def _args @_args end |
#requested_command ⇒ Object
Storage for the extracted command.
59 60 61 |
# File 'lib/brainstem/cli.rb', line 59 def requested_command @requested_command end |
Class Method Details
.call(args, options = {}) ⇒ Brainstem::Cli
Convenience for instantiating and calling the Cli object.
19 20 21 |
# File 'lib/brainstem/cli.rb', line 19 def self.call(args, = {}) new(args, ).call end |
Instance Method Details
#call ⇒ Brainstem::Cli
Routes to an application endpoint depending on given options.
41 42 43 44 45 46 47 48 49 |
# File 'lib/brainstem/cli.rb', line 41 def call if requested_command && commands.has_key?(requested_command) self.command_method = commands[requested_command].method(:call) end command_method.call(_args.drop(1)) self end |