Skip to content

Commit 334f9e5

Browse files
authored
Land rapid7#18893, updates the help command to consistently format columns
2 parents b91430c + d51aa30 commit 334f9e5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/rex/ui/text/dispatcher_shell.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def cmd_help_tabs(str, words)
232232
#
233233
# Return a pretty, user-readable table of commands provided by this
234234
# dispatcher.
235+
# The command column width can be modified by passing in :command_width.
235236
#
236237
def help_to_s(opts={})
237238
# If this dispatcher has no commands, we can't do anything useful.
@@ -250,7 +251,7 @@ def help_to_s(opts={})
250251
{
251252
'Command' =>
252253
{
253-
'Width' => 12
254+
'Width' => opts[:command_width]
254255
}
255256
})
256257

@@ -656,8 +657,10 @@ def current_dispatcher
656657
def help_to_s(opts = {})
657658
str = ''
658659

660+
max_command_length = dispatcher_stack.flat_map { |dispatcher| dispatcher.commands.to_a }.map { |(name, _description)| name.length }.max
661+
659662
dispatcher_stack.reverse.each { |dispatcher|
660-
str << dispatcher.help_to_s
663+
str << dispatcher.help_to_s(opts.merge({ command_width: [max_command_length, 12].max }))
661664
}
662665

663666
return str

0 commit comments

Comments
 (0)