mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Group commands in "help" output
This commit is contained in:
parent
c97ecf0b25
commit
0c65a06f72
2 changed files with 37 additions and 7 deletions
|
@ -129,6 +129,25 @@ class Pry
|
|||
obj
|
||||
end
|
||||
end
|
||||
|
||||
# The group in which the command should be displayed in "help" output.
|
||||
# This is usually auto-generated from directory naming, but it can be
|
||||
# manually overridden if necessary.
|
||||
def group(name=nil)
|
||||
@group = name if name
|
||||
@group ||=(
|
||||
case Pry::Method(block).source_file
|
||||
when %r{/pry/.*_commands/(.*).rb}
|
||||
$1.capitalize
|
||||
when %r{/(pry-[^\/]*)/}
|
||||
$1
|
||||
when /pryrc/
|
||||
"~/.pryrc"
|
||||
else
|
||||
"(other)"
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -350,16 +350,27 @@ class Pry
|
|||
output.puts "No info for command: #{cmd}"
|
||||
end
|
||||
else
|
||||
output.puts
|
||||
help_text = heading("Command List: ") + "\n"
|
||||
grouped = commands.values.group_by(&:group)
|
||||
|
||||
help_text << commands.map do |key, command|
|
||||
if command.description && !command.description.empty?
|
||||
"#{command.options[:listing].to_s.ljust(18)} #{command.description}"
|
||||
help_text = []
|
||||
|
||||
grouped.keys.sort.each do |key|
|
||||
|
||||
commands = grouped[key].select do |command|
|
||||
command.description && !command.description.empty?
|
||||
end.sort_by do |command|
|
||||
command.options[:listing].to_s
|
||||
end
|
||||
end.compact.sort.join("\n")
|
||||
|
||||
stagger_output(help_text)
|
||||
unless commands.empty?
|
||||
help_text << " #{text.bold(key)}"
|
||||
help_text += commands.map do |command|
|
||||
"#{command.options[:listing].to_s.ljust(18)} #{command.description}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
stagger_output(help_text.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue