def help_message
commands_info = IRB::Command.all_commands_info
helper_methods_info = IRB::HelperMethod.all_helper_methods_info
commands_grouped_by_categories = commands_info.group_by { |cmd| cmd[:category] }
commands_grouped_by_categories["Helper methods"] = helper_methods_info
if irb_context.with_debugger
commands_grouped_by_categories.delete("Debugging")
end
longest_cmd_name_length = commands_info.map { |c| c[:display_name].length }.max
output = StringIO.new
help_cmds = commands_grouped_by_categories.delete("Help")
no_category_cmds = commands_grouped_by_categories.delete("No category")
aliases = irb_context.instance_variable_get(:@command_aliases).map do |alias_name, target|
{ display_name: alias_name, description: "Alias for `#{target}`" }
end
add_category_to_output("Help", help_cmds, output, longest_cmd_name_length)
commands_grouped_by_categories.each do |category, cmds|
add_category_to_output(category, cmds, output, longest_cmd_name_length)
end
if no_category_cmds
add_category_to_output("No category", no_category_cmds, output, longest_cmd_name_length)
end
add_category_to_output("Aliases", aliases, output, longest_cmd_name_length)
if irb_context.with_debugger
add_category_to_output("Debugging (from debug.gem)", [], output, longest_cmd_name_length)
output.puts DEBUGGER__.help
end
output.string
end