module Fuelcell::Action::Subcommands

Public Instance Methods

<<(cmds)
Alias for: add
[](name) click to toggle source
# File lib/fuelcell/action/subcommands.rb, line 13
def [](name)
  list = name.split(' ')
  deep_find(self, list)
end
add(cmds) click to toggle source
# File lib/fuelcell/action/subcommands.rb, line 7
def add(cmds)
  cmds = [cmds] unless cmds.is_a?(Array)
  cmds.each { |cmd|  subcommands[cmd.name] = cmd }
end
Also aliased as: <<
exist?(name) click to toggle source
# File lib/fuelcell/action/subcommands.rb, line 18
def exist?(name)
  list   = name.split(' ')
  result = deep_find(self, list)
  result.is_a?(NotFound) ? false : true
end
global_options(target) click to toggle source

Collect global options from the option manager of every command in the Hierarchy

@return [Hash]

# File lib/fuelcell/action/subcommands.rb, line 36
def global_options(target)
  collect_global_options(target, self, {})
end

Protected Instance Methods

collect_global_options(target, cmd, list) click to toggle source
# File lib/fuelcell/action/subcommands.rb, line 68
def collect_global_options(target, cmd, list)
  return list if target === cmd

  globals = cmd.opts.globals
  list.merge!(globals)

  return list if cmd.empty?

  cmd.each do |_, subcommand|
    collect_global_options(target, subcommand, list)
  end
  list
end
create_tree(current_cmd, tree) click to toggle source
# File lib/fuelcell/action/subcommands.rb, line 57
def create_tree(current_cmd, tree)
  while search_key = tree.shift
    unless current_cmd.exist?(search_key)
      current_cmd.command(search_key) {}
    end
    child = current_cmd[search_key]
    create_tree(child, tree)
  end
  child
end
deep_find(cmd, names) click to toggle source
# File lib/fuelcell/action/subcommands.rb, line 46
def deep_find(cmd, names)
  return cmd if names.empty?

  name = names.shift
  unless cmd.subcommands.key?(name)
    names.unshift name
    return NotFound.new(names)
  end
  deep_find(cmd.subcommands[name], names)
end
subcommands() click to toggle source
# File lib/fuelcell/action/subcommands.rb, line 42
def subcommands
  @subcommands ||= {}
end