Class: Fuelcell::Action::Root
- Defined in:
- lib/fuelcell/action/root.rb
Overview
Top most command in the command hierarchy. The root command holds all other commands that would appear on the command line, it holds the name of the script that uses it.
Instance Attribute Summary collapse
-
#help ⇒ Object
readonly
Returns the value of attribute help.
Attributes inherited from Command
Instance Method Summary collapse
- #ensure_command_hierarchy(cmd_args) ⇒ Object
-
#initialize(name = nil) ⇒ Root
constructor
A new instance of Root.
-
#locate(cmd_args, raw_args = []) ⇒ Object
Find any command in the root command.
Methods inherited from Command
#add_global_options, #command, #desc, #usage
Methods included from Callable
Methods included from Subcommands
#[], #add, #exist?, #global_options, #search
Constructor Details
#initialize(name = nil) ⇒ Root
Returns a new instance of Root.
9 10 11 12 13 |
# File 'lib/fuelcell/action/root.rb', line 9 def initialize(name = nil) name = script_name if name.nil? super(name) install_help end |
Instance Attribute Details
#help ⇒ Object (readonly)
Returns the value of attribute help.
7 8 9 |
# File 'lib/fuelcell/action/root.rb', line 7 def help @help end |
Instance Method Details
#ensure_command_hierarchy(cmd_args) ⇒ Object
49 50 51 |
# File 'lib/fuelcell/action/root.rb', line 49 def ensure_command_hierarchy(cmd_args) create_tree(self, cmd_args) end |
#locate(cmd_args, raw_args = []) ⇒ Object
Find any command in the root command.
Using the cmd_args, which form a command hierarchy, we search for the deepest sub command first. If that it not found we assume that command arg is really a regular arg and we put it back. We do this until we reach the top command
Parameters:
- cmd_args <Array>
-
A hierarchal list of commands to be searched
- remaining_args <Array>
-
All remaining raw args from ARGV
Returns:
<Fuelcell::Command> command object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fuelcell/action/root.rb', line 28 def locate(cmd_args, raw_args = []) return self if cmd_args.empty? target = NotFound.new(cmd_args) loop do terms = cmd_args.dup break if cmd_args.empty? target = search(terms) break unless target.is_a?(NotFound) raw_args.unshift(cmd_args.pop) end # this must be an arg for the root command's action and not a command return self if callable? && target.is_a?(NotFound) target end |