Class: Fuelcell::Action::Command
- Inherits:
-
Object
- Object
- Fuelcell::Action::Command
- Extended by:
- Forwardable
- Includes:
- Callable, Subcommands
- Defined in:
- lib/fuelcell/action/command.rb
Overview
Represents the action you want to perform. It also holds a list of option definitions used by the parser, along with meta data used by the help system and callable which is any object that implements call, this is your action.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#add_global_options(cmd) ⇒ Fuelcell::Action::Command
Allows all the global option definitions from this command hierarchy to be add to the command given.
-
#command(key) { ... } ⇒ Object
Allows a command to add subcommands to itself.
-
#desc(text = nil) ⇒ String
Both getting and setter for description.
-
#initialize(name) ⇒ Command
constructor
Every command initializes with only its name set expecting the dsl to finish assigning the rest of its properties.
-
#usage(text = nil, desc_text = nil) ⇒ String
This will assign both usage text and description, but when called with no args it will get the usage.
Methods included from Callable
Methods included from Subcommands
#[], #add, #exist?, #global_options, #search
Constructor Details
#initialize(name) ⇒ Command
Every command initializes with only its name set expecting the dsl to finish assigning the rest of its properties
21 22 23 24 25 26 27 |
# File 'lib/fuelcell/action/command.rb', line 21 def initialize(name) @name = name.to_s @usage = nil @desc = nil @opts = OptsManager.new @args = ArgsManager.new end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/fuelcell/action/command.rb', line 8 def args @args end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/fuelcell/action/command.rb', line 8 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/fuelcell/action/command.rb', line 8 def opts @opts end |
Instance Method Details
#add_global_options(cmd) ⇒ Fuelcell::Action::Command
Allows all the global option definitions from this command hierarchy to be add to the command given
66 67 68 69 70 71 72 |
# File 'lib/fuelcell/action/command.rb', line 66 def (cmd) return cmd if self === cmd (cmd).each do |_key, opt_definition| cmd.opt opt_definition end cmd end |
#command(key) { ... } ⇒ Object
Allows a command to add subcommands to itself
55 56 57 58 59 |
# File 'lib/fuelcell/action/command.rb', line 55 def command(key, &block) cmd = Command.new(key) cmd.instance_eval(&block) add cmd end |
#desc(text = nil) ⇒ String
Both getting and setter for description
45 46 47 48 |
# File 'lib/fuelcell/action/command.rb', line 45 def desc(text = nil) return @desc if text.nil? @desc = text end |
#usage(text = nil, desc_text = nil) ⇒ String
This will assign both usage text and description, but when called with no args it will get the usage
35 36 37 38 39 |
# File 'lib/fuelcell/action/command.rb', line 35 def usage(text = nil, desc_text = nil) return @usage if text.nil? desc(desc_text) unless desc_text.nil? @usage = text end |