Sha256: d1eccd59e85233ed5dec31cc55f9c47ecdf5a63344751c9295a2351eb91a8bb5

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

# Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
require_relative 'base/cmd'

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

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

Add an alias for a COMMAND

See also 'unalias'.
    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 alias))
    elsif args.size == 2
      @proc.commands['show'].run(['show', 'alias', 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 %W(cmd.name yy step)
  cmd.run %W(cmd.name)
  cmd.run %W(cmd.name yy next)
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trepanning-0.1.0 processor/command/alias.rb
trepanning-0.0.9 processor/command/alias.rb
trepanning-0.0.8 processor/command/alias.rb
trepanning-0.0.6 processor/command/alias.rb