File tree Expand file tree Collapse file tree 4 files changed +42
-18
lines changed
Expand file tree Collapse file tree 4 files changed +42
-18
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
188echo
9+ % end
Original file line number Diff line number Diff line change 1515 cli --version | -v
1616
1717Commands:
18- connect Connect to the metaverse
18+ connect Connect to the metaverse
1919
2020+ ./cli -h
2121cli - Sample application with private commands
2626 cli --version | -v
2727
2828Commands:
29- connect Connect to the metaverse
29+ connect Connect to the metaverse
3030
3131Options:
3232 --help, -h
You can’t perform that action at this time.
0 commit comments