Sha256: 630a0280c00c493515d88a2b9a9630f7a3fdc8fb972d28f89fca6e91b12ed331

Contents?: true

Size: 1.8 KB

Versions: 6

Compression:

Stored size: 1.8 KB

Contents

require 'rubygems'; require 'require_relative'
require_relative '../../app/options'
module Trepan

  # Implements debugger "help" command.
  class HelpCommand < OldCommand
    self.allow_in_control = true

    # An input line is matched against this regular expression. If we have
    # a match, run this command.
    def regexp
      /^\s* h(?:elp)? (?:\s+(.+))? $/x
    end

    # The code that implements this command.
    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 "#{Trepan::PROGRAM} help v#{Trepan::VERSION}\n" unless
            self.class.settings[:debuggertesting]
          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, self.class.settings[:width])
        end
      end
      print "\n"
    end

    class << self
      # The command name listed via 'help'
      def help_command
        'help'
      end

      # Returns a String given the help description of this command
      def help(cmd)
        %{
          h[elp]\t\tprint this help
          h[elp] command\tprint help on command
        }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rb8-trepanning-0.1.6 processor/command-ruby-debug/help.rb
rb8-trepanning-0.1.5 processor/command-ruby-debug/help.rb
rb8-trepanning-0.1.4 processor/command-ruby-debug/help.rb
rb8-trepanning-0.1.3 processor/command-ruby-debug/help.rb
rb8-trepanning-0.1.3-universal-ruby-1.9.2 processor/command-ruby-debug/help.rb
rb8-trepanning-0.1.3-universal-ruby-1.8.7 processor/command-ruby-debug/help.rb