class Fuelcell::Action::Root

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.

Attributes

help[R]

Public Class Methods

new(name = nil) click to toggle source
Calls superclass method Fuelcell::Action::Command::new
# File lib/fuelcell/action/root.rb, line 9
def initialize(name = nil)
  name = script_name if name.nil?
  super(name)
  install_help
end

Public Instance Methods

ensure_command_hierarchy(cmd_args) click to toggle source
# 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 = []) click to toggle source

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

# 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

Private Instance Methods

callable_helper() click to toggle source
# File lib/fuelcell/action/root.rb, line 67
def callable_helper
  root = self
  lambda do |_opts, args, shell|
    text = Fuelcell::Help.generate(root, args, shell.terminal_width)
    shell.puts text
  end
end
install_help() click to toggle source
# File lib/fuelcell/action/root.rb, line 59
def install_help
  helper = callable_helper
  command 'help' do
    usage '[COMMAND]', 'describes subcommands or a specific command'
    run helper
  end
end
script_name() click to toggle source
# File lib/fuelcell/action/root.rb, line 55
def script_name
  File.basename($PROGRAM_NAME, File.extname($PROGRAM_NAME))
end