Class: Byebug::HelpCommand

Inherits:
Command
  • Object
show all
Includes:
Columnize
Defined in:
lib/byebug/commands/help.rb

Overview

Implements byebug “help” command.

Constant Summary

Constants inherited from Command

Command::DEF_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, help, inherited, #initialize, load_commands, #match, method_missing, options, register_setting_get, register_setting_set, register_setting_var, settings, settings_map

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



43
44
45
46
47
48
# File 'lib/byebug/commands/help.rb', line 43

def description
  %{
    h[elp]\t\tprint this help
    h[elp] command\tprint help on command
  }
end

.namesObject



39
40
41
# File 'lib/byebug/commands/help.rb', line 39

def names
  %w(help)
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/byebug/commands/help.rb', line 13

def execute
  if @match[1]
    args = @match[1].split
    cmds = @state.commands.select { |cmd| cmd.names.include?(args[0]) }
    unless cmds.empty?
      help = cmds.map{ |cmd| cmd.help(args) }.join
      help = help.split("\n").map{|l| l.gsub(/^ +/, '')}
      help.shift if help.first && help.first.empty?
      help.pop if help.last && help.last.empty?
      return print help.join("\n") + "\n"
    else
      return errmsg "Undefined command: \"#{args[0]}\".  Try \"help\".\n" if
        args[0]
    end
  end

  print "byebug help v#{Byebug::VERSION}\n" unless
    Command.settings[:testing]

  print "Type \"help <command-name>\" for help on a specific command\n\n"
  print "Available commands:\n"
  cmds = @state.commands.map{ |cmd| cmd.names }.flatten.uniq.sort
  print columnize(cmds, Command.settings[:width])
end

#regexpObject



9
10
11
# File 'lib/byebug/commands/help.rb', line 9

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