module Bashly::Script::Introspection::Commands

Public Instance Methods

command_aliases() click to toggle source

Returns a full list of the Command names and aliases combined

# File lib/bashly/script/introspection/commands.rb, line 6
def command_aliases
  commands.map(&:aliases).flatten
end
command_help_data() click to toggle source

Returns a data structure for displaying subcommands help

# File lib/bashly/script/introspection/commands.rb, line 11
def command_help_data
  result = {}

  commands.each do |command|
    result[command.group_string] ||= {}
    result[command.group_string][command.name] = {
      summary:    command.summary_string,
      visibility: command.visibility,
    }
    next unless command.expose

    command.commands.each do |subcommand|
      result[command.group_string]["#{command.name} #{subcommand.name}"] = {
        summary:    subcommand.summary_string,
        visibility: subcommand.visibility,
        help_only:  command.expose != 'always',
      }
    end
  end

  result
end
command_names() click to toggle source

Returns only the names of the Commands

# File lib/bashly/script/introspection/commands.rb, line 35
def command_names
  commands.map(&:name)
end
commands() click to toggle source

Returns an array of the Commands

# File lib/bashly/script/introspection/commands.rb, line 40
def commands
  return [] unless options['commands']

  options['commands'].map do |options|
    result = Command.new options
    result.parents = parents + [name]
    result.parent_command = self
    result
  end
end
deep_commands(include_self: false) click to toggle source

Returns a flat array containing all the commands in this tree. This includes children + grandchildren (recursive), and may include self

# File lib/bashly/script/introspection/commands.rb, line 53
def deep_commands(include_self: false)
  result = []
  result << self if include_self
  commands.each do |command|
    result << command
    if command.commands.any?
      result += command.deep_commands
    end
  end
  result
end
default_command() click to toggle source

If any of this command’s subcommands has the default option set to true, this default command will be returned, nil otherwise.

# File lib/bashly/script/introspection/commands.rb, line 67
def default_command
  commands.find(&:default)
end
grouped_commands() click to toggle source

Returns subcommands by group

# File lib/bashly/script/introspection/commands.rb, line 72
def grouped_commands
  result = {}

  visible_commands.each do |command|
    result[command.group_string] ||= []
    result[command.group_string] << command
    next unless command.expose

    command.visible_commands.each do |subcommand|
      result[command.group_string] << subcommand
    end
  end

  result
end
public_command_aliases() click to toggle source

Returns a full list of the public Command names and aliases combined

# File lib/bashly/script/introspection/commands.rb, line 94
def public_command_aliases
  public_commands.map(&:aliases).flatten
end
public_commands() click to toggle source

Returns only commands that are not private

# File lib/bashly/script/introspection/commands.rb, line 89
def public_commands
  commands.reject(&:private)
end
visible_command_aliases() click to toggle source

Returns a full list of the visible Command names and aliases combined

# File lib/bashly/script/introspection/commands.rb, line 105
def visible_command_aliases
  visible_commands.map(&:aliases).flatten
end
visible_commands() click to toggle source

Returns only public commands, or both public and private commands if Settings.private_reveal_key is set

# File lib/bashly/script/introspection/commands.rb, line 100
def visible_commands
  Settings.private_reveal_key ? commands : public_commands
end