Sha256: a580e38fe68a924bd71e2c3988547b0dc5dd68db634e622b54ef4273d3499110

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

require 'byebug/command'
require 'byebug/errors'

module Byebug
  #
  # Ask for help from byebug's prompt.
  #
  class HelpCommand < Command
    self.allow_in_control = true
    self.allow_in_post_mortem = true

    def self.regexp
      /^\s* h(?:elp)? (?:\s+(\S+))? (?:\s+(\S+))? \s*$/x
    end

    def self.description
      <<-EOD
        h[elp][ <cmd>[ <subcmd>]]

        #{short_description}

        help                -- prints a summary of all commands
        help <cmd>          -- prints help on command <cmd>
        help <cmd> <subcmd> -- prints help on <cmd>'s subcommand <subcmd>
      EOD
    end

    def self.short_description
      'Helps you using byebug'
    end

    def execute
      return help_for_all unless @match[1]

      return help_for(@match[1], command) unless @match[2]

      help_for(@match[2], subcommand)
    end

    private

    def help_for_all
      puts(processor.command_list.to_s)
    end

    def help_for(input, cmd)
      fail CommandNotFound.new(input, command) unless cmd

      puts(cmd.help)
    end

    def command
      @command ||= processor.command_list.match(@match[1])
    end

    def subcommand
      return unless command

      @subcommand ||= command.subcommand_list.match(@match[2])
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
byebug-8.2.2 lib/byebug/commands/help.rb
byebug-8.2.1 lib/byebug/commands/help.rb
byebug-8.2.0 lib/byebug/commands/help.rb
byebug-8.1.0 lib/byebug/commands/help.rb
byebug-8.0.1 lib/byebug/commands/help.rb
byebug-8.0.0 lib/byebug/commands/help.rb
byebug-7.0.0 lib/byebug/commands/help.rb
byebug-6.0.2 lib/byebug/commands/help.rb
byebug-6.0.0 lib/byebug/commands/help.rb