1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
# frozen_string_literal: true
require_relative "../command"
require_relative "../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
<<-DESCRIPTION
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>
DESCRIPTION
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)
raise 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
|