\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/cpanel/ea-ruby27/root/usr/local/share/gems/gems/irb-1.18.0/lib/irb/command/

Viewing File: help.rb

# frozen_string_literal: true

module IRB
  module Command
    class Help < Base
      category "Help"
      description "List all available commands. Use `help <command>` to get information about a specific command."

      def execute(command_name)
        content =
          if command_name.empty?
            help_message
          else
            if command_class = Command.load_command(command_name)
              command_class.help_message || command_class.description
            else
              "Can't find command `#{command_name}`. Please check the command name and try again.\n\n"
            end
          end
        Pager.page_content(content)
      end

      private

      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
          # Remove the original "Debugging" category
          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

        # Display help commands first
        add_category_to_output("Help", help_cmds, output, longest_cmd_name_length)

        # Display the rest of the commands grouped by categories
        commands_grouped_by_categories.each do |category, cmds|
          add_category_to_output(category, cmds, output, longest_cmd_name_length)
        end

        # Display commands without a category
        if no_category_cmds
          add_category_to_output("No category", no_category_cmds, output, longest_cmd_name_length)
        end

        # Display aliases
        add_category_to_output("Aliases", aliases, output, longest_cmd_name_length)

        # Append the debugger help at the end
        if irb_context.with_debugger
          # Add "Debugging (from debug.gem)" category as title
          add_category_to_output("Debugging (from debug.gem)", [], output, longest_cmd_name_length)
          output.puts DEBUGGER__.help
        end

        output.string
      end

      def add_category_to_output(category, cmds, output, longest_cmd_name_length)
        output.puts Color.colorize(category, [:BOLD])

        cmds.each do |cmd|
          output.puts "  #{cmd[:display_name].to_s.ljust(longest_cmd_name_length)}    #{cmd[:description]}"
        end

        output.puts
      end
    end
  end
end