Module: Bashly::Script::Introspection::Commands
- Included in:
- Command
- Defined in:
- lib/bashly/script/introspection/commands.rb
Instance Method Summary collapse
-
#command_aliases ⇒ Object
Returns a full list of the Command names and aliases combined.
-
#command_help_data ⇒ Object
Returns a data structure for displaying subcommands help.
-
#command_names ⇒ Object
Returns only the names of the Commands.
-
#commands ⇒ Object
Returns an array of the Commands.
-
#deep_commands(include_self: false) ⇒ Object
Returns a flat array containing all the commands in this tree.
-
#default_command ⇒ Object
If any of this command’s subcommands has the default option set to true, this default command will be returned, nil otherwise.
-
#grouped_commands ⇒ Object
Returns subcommands by group.
-
#public_command_aliases ⇒ Object
Returns a full list of the public Command names and aliases combined.
-
#public_commands ⇒ Object
Returns only commands that are not private.
-
#visible_command_aliases ⇒ Object
Returns a full list of the visible Command names and aliases combined.
-
#visible_commands ⇒ Object
Returns only public commands, or both public and private commands if Settings.private_reveal_key is set.
Instance Method Details
#command_aliases ⇒ Object
Returns a full list of the Command names and aliases combined
6 7 8 |
# File 'lib/bashly/script/introspection/commands.rb', line 6 def command_aliases commands.map(&:aliases).flatten end |
#command_help_data ⇒ Object
Returns a data structure for displaying subcommands help
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 ⇒ Object
Returns only the names of the Commands
35 36 37 |
# File 'lib/bashly/script/introspection/commands.rb', line 35 def command_names commands.map(&:name) end |
#commands ⇒ Object
Returns an array of the Commands
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bashly/script/introspection/commands.rb', line 40 def commands return [] unless ['commands'] ['commands'].map do || result = Command.new result.parents = parents + [name] result.parent_command = self result end end |
#deep_commands(include_self: false) ⇒ Object
Returns a flat array containing all the commands in this tree. This includes children + grandchildren (recursive), and may include self
53 54 55 56 57 58 59 60 61 62 63 |
# 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 ⇒ Object
If any of this command’s subcommands has the default option set to true, this default command will be returned, nil otherwise.
67 68 69 |
# File 'lib/bashly/script/introspection/commands.rb', line 67 def default_command commands.find(&:default) end |
#grouped_commands ⇒ Object
Returns subcommands by group
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# 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 ⇒ Object
Returns a full list of the public Command names and aliases combined
94 95 96 |
# File 'lib/bashly/script/introspection/commands.rb', line 94 def public_command_aliases public_commands.map(&:aliases).flatten end |
#public_commands ⇒ Object
Returns only commands that are not private
89 90 91 |
# File 'lib/bashly/script/introspection/commands.rb', line 89 def public_commands commands.reject(&:private) end |
#visible_command_aliases ⇒ Object
Returns a full list of the visible Command names and aliases combined
105 106 107 |
# File 'lib/bashly/script/introspection/commands.rb', line 105 def visible_command_aliases visible_commands.map(&:aliases).flatten end |
#visible_commands ⇒ Object
Returns only public commands, or both public and private commands if Settings.private_reveal_key is set
100 101 102 |
# File 'lib/bashly/script/introspection/commands.rb', line 100 def visible_commands Settings.private_reveal_key ? commands : public_commands end |