Module: Bashly::Script::Introspection::Commands
- Included in:
- Command
- Defined in:
- lib/bashly/script/introspection/commands.rb
Instance Method Summary collapse
-
#catch_all_used_anywhere? ⇒ Boolean
Returns true if the command or any of its descendants has ‘catch_all`.
-
#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
#catch_all_used_anywhere? ⇒ Boolean
Returns true if the command or any of its descendants has ‘catch_all`
6 7 8 |
# File 'lib/bashly/script/introspection/commands.rb', line 6 def catch_all_used_anywhere? deep_commands(include_self: true).any? { |x| x.catch_all.enabled? } end |
#command_aliases ⇒ Object
Returns a full list of the Command names and aliases combined
11 12 13 |
# File 'lib/bashly/script/introspection/commands.rb', line 11 def command_aliases commands.map(&:aliases).flatten end |
#command_help_data ⇒ Object
Returns a data structure for displaying subcommands help
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bashly/script/introspection/commands.rb', line 16 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
40 41 42 |
# File 'lib/bashly/script/introspection/commands.rb', line 40 def command_names commands.map(&:name) end |
#commands ⇒ Object
Returns an array of the Commands
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bashly/script/introspection/commands.rb', line 45 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
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bashly/script/introspection/commands.rb', line 58 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.
72 73 74 |
# File 'lib/bashly/script/introspection/commands.rb', line 72 def default_command commands.find(&:default) end |
#grouped_commands ⇒ Object
Returns subcommands by group
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bashly/script/introspection/commands.rb', line 77 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
99 100 101 |
# File 'lib/bashly/script/introspection/commands.rb', line 99 def public_command_aliases public_commands.map(&:aliases).flatten end |
#public_commands ⇒ Object
Returns only commands that are not private
94 95 96 |
# File 'lib/bashly/script/introspection/commands.rb', line 94 def public_commands commands.reject(&:private) end |
#visible_command_aliases ⇒ Object
Returns a full list of the visible Command names and aliases combined
110 111 112 |
# File 'lib/bashly/script/introspection/commands.rb', line 110 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
105 106 107 |
# File 'lib/bashly/script/introspection/commands.rb', line 105 def visible_commands Settings.private_reveal_key ? commands : public_commands end |