Sha256: 6bc5a0e9f22560e8615ed96b5a2c5758cbb02a2eea8941f704945e8974783e83

Contents?: true

Size: 936 Bytes

Versions: 3

Compression:

Stored size: 936 Bytes

Contents

# frozen_string_literal: true

require "stringio"
require_relative "nop"

module IRB
  # :stopdoc:

  module ExtendCommand
    class ShowCmds < Nop
      category "IRB"
      description "List all available commands and their description."

      def execute(*args)
        commands_info = IRB::ExtendCommandBundle.all_commands_info
        commands_grouped_by_categories = commands_info.group_by { |cmd| cmd[:category] }
        longest_cmd_name_length = commands_info.map { |c| c[:display_name].length }.max

        output = StringIO.new

        commands_grouped_by_categories.each do |category, cmds|
          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

        puts output.string

        nil
      end
    end
  end

  # :startdoc:
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
irb-1.7.4 lib/irb/cmd/show_cmds.rb
irb-1.7.3 lib/irb/cmd/show_cmds.rb
irb-1.7.2 lib/irb/cmd/show_cmds.rb