Sha256: d42122cd7124d18f75d5aaad70e1ccaf5956b9d34f220088b90134c1cc8de295

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module Byebug

  # Implements byebug "help" command.
  class HelpCommand < Command
    include Columnize
    self.allow_in_control = true

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

    def execute
      if @match[1]
        args = @match[1].split
        cmds = @state.commands.select do |cmd|
          [cmd.help_command].flatten.include?(args[0])
        end
      else
        args = @match[1]
        cmds = []
      end
      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?
        print help.join("\n")
      else
        if args and args[0]
          errmsg "Undefined command: \"#{args[0]}\".  Try \"help\"."
        else
          print "byebug help v#{Byebug::VERSION}\n" unless
            self.class.settings[:byebugtesting]
          print "Type 'help <command-name>' for help on a specific command\n\n"
          print "Available commands:\n"
          cmds = @state.commands.map{ |cmd| cmd.help_command }
          cmds = cmds.flatten.uniq.sort
          print columnize(cmds, Command.settings[:width])
        end
      end
      print "\n"
    end

    class << self
      def help_command
        'help'
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
byebug-1.1.0 lib/byebug/commands/help.rb