Sha256: 3ad2fc7bc50a869a6fb967c4e51a20ff00102d77af14b7f3cb7dacee2340c582

Contents?: true

Size: 1.86 KB

Versions: 6

Compression:

Stored size: 1.86 KB

Contents

# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
require 'rubygems'; require 'require_relative'
require_relative '../command'

class Trepan::Command::AliasCommand < Trepan::Command

  unless defined?(HELP)
    NAME = File.basename(__FILE__, '.rb')
    HELP = <<-HELP
#{NAME} ALIAS COMMAND

Add alias ALIAS for a debugger command COMMAND.  

Add an alias when you want to use a command abbreviation for a command
that would otherwise be ambigous. For example, by default we make 's'
be an alias of 'step' to force it to be used. Without the alias, "s"
might be "step", "show", or "set" among others

Example:

alias cat list   # "cat rubyfile.rb" is the same as "list rubyfile.rb"
alias s   step   # "s" is now an alias for "step".
                 # The above examples done by default.

See also 'unalias' and 'show #{NAME}'.
    HELP

    CATEGORY      = 'support'
    MAX_ARGS      = 2  # Need at most this many
    NEED_STACK    = true
    SHORT_HELP    = 'Add an alias for a debugger command'
  end
  
  # Run command. 
  def run(args)
    if args.size == 1
      @proc.commands['show'].run(%W(show #{NAME}))
    elsif args.size == 2
      @proc.commands['show'].run(%W(show #{NAME} #{args[1]}))
    else
      junk, al, command = args
      old_command = @proc.aliases[al]
      if @proc.commands.member?(command)
        @proc.aliases[al] = command
        if old_command
          msg("Alias '#{al}' for command '#{command}' replaced old " + 
              "alias for '#{old_command}'.")
        else
          msg "New alias '#{al}' for command '#{command}' created."
        end
      else
        errmsg "You must alias to a command name, and '#{command}' isn't one."
      end
    end
  end
end

if __FILE__ == $0
  # Demo it.
  require_relative '../mock'
  dbgr, cmd = MockDebugger::setup
  cmd.run %W(#{cmd.name} yy foo)
  cmd.run [cmd.name]
  cmd.run %W(cmd.name yy alias)
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
rbx-trepanning-0.2.1-universal-rubinius-2.0 processor/command/alias.rb
rbx-trepanning-0.2.1-universal-rubinius-1.2 processor/command/alias.rb
rbx-trepanning-0.2.0-universal-rubinius-2.0 processor/command/alias.rb
rb8-trepanning-0.1.5 processor/command/alias.rb
rbx-trepanning-0.1.0-universal-rubinius-1.2 processor/command/alias.rb
rb8-trepanning-0.1.4 processor/command/alias.rb