Skip to content

Commit aeef258

Browse files
committed
- Add command.deep_help option
1 parent 7de6544 commit aeef258

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

lib/bashly/concerns/command_scopes.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,39 @@ def required_flags
7070
flags.select &:required
7171
end
7272

73+
# Returns a data structure for displaying subcommands help
74+
def commands_help_data
75+
group_string = strings[:commands]
76+
result = {}
77+
78+
commands.reject(&:private).each do |command|
79+
summary = if command.default
80+
strings[:default_command_summary] % { summary: command.summary }
81+
else
82+
command.summary
83+
end
84+
85+
group_string = strings[:group] % { group: command.group } if command.group
86+
87+
result[group_string] ||= {}
88+
result[group_string][command.name] = summary
89+
90+
if command.deep_help
91+
command.commands.reject(&:private).each do |subcommand|
92+
sub_summary = if subcommand.default
93+
strings[:default_command_summary] % { summary: subcommand.summary }
94+
else
95+
subcommand.summary
96+
end
97+
98+
result[group_string]["#{command.name} #{subcommand.name}"] = sub_summary
99+
end
100+
end
101+
end
102+
103+
result
104+
end
105+
73106
# Returns an array of all the args with a whitelist
74107
def whitelisted_args
75108
args.select &:allowed

lib/bashly/script/command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class << self
88
def option_keys
99
@option_keys ||= %i[
1010
alias args catch_all commands completions
11-
default dependencies environment_variables examples
11+
deep_help default dependencies environment_variables examples
1212
extensible filename filters flags
1313
footer group help name
1414
private version
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
<%= view_marker %>
2-
% unless commands.first.group
3-
printf "<%= strings[:commands] %>\n"
4-
% end
5-
% maxlen = command_names.map(&:size).max
6-
% commands.reject(&:private).each do |command|
7-
% summary = command.summary
8-
% summary = strings[:default_command_summary] % { summary: summary } if command.default
9-
% if command.group
10-
% if command.name == commands.first.name
11-
printf "<%= strings[:group] % { group: command.group } %>\n"
12-
% else
13-
printf "\n<%= strings[:group] % { group: command.group } %>\n"
14-
% end
15-
% end
16-
echo " <%= command.name.ljust maxlen %> <%= summary %>"
2+
% maxlen = commands_help_data.values.map(&:keys).flatten.map(&:size).max
3+
% commands_help_data.each do |group, commands|
4+
printf "<%= group %>\n"
5+
% commands.each do |command, summary|
6+
echo " <%= command.ljust maxlen %> <%= summary %>"
177
% end
188
echo
9+
% end

spec/approvals/examples/command-private

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Usage:
1515
cli --version | -v
1616

1717
Commands:
18-
connect Connect to the metaverse
18+
connect Connect to the metaverse
1919

2020
+ ./cli -h
2121
cli - Sample application with private commands
@@ -26,7 +26,7 @@ Usage:
2626
cli --version | -v
2727

2828
Commands:
29-
connect Connect to the metaverse
29+
connect Connect to the metaverse
3030

3131
Options:
3232
--help, -h

0 commit comments

Comments
 (0)