Sha256: 055f175d727608c56829a5edf6059586c790c949193e93f8209acac086eaef31

Contents?: true

Size: 1.66 KB

Versions: 5

Compression:

Stored size: 1.66 KB

Contents

# -*- coding: utf-8 -*-
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
require 'rubygems'; require 'require_relative'
require_relative '../base/subcmd'
require_relative '../../../app/complete'

class Trepan::Subcommand::InfoMacro < Trepan::Subcommand
  unless defined?(HELP)
    Trepanning::Subcommand.set_name_prefix(__FILE__, self)
    HELP = <<-HELP
#{CMD} 
#{CMD} *
#{CMD} MACRO1 [MACRO2 ..]

In the first form a list of the existing macro names are shown
in column format.

In the second form, all macro names and their definitions are show.

In the last form the only definitions of the given macro names is shown.
    HELP
    SHORT_HELP = "Info defined macros"
    MIN_ABBREV = 'ma'.size
  end

  def complete(prefix)
    Trepan::Complete.complete_token(@proc.macros.keys + %w(*), prefix)
  end

  def run(args)
    if args.size > 2
      macro_names = 
        if args.size == 3 && '*' == args[2] 
          @proc.macros.keys
        else
          args[2..-1]
        end        
      macro_names.each do |macro_name|
        if @proc.macros.member?(macro_name)
          section "#{macro_name}:"
          string = @proc.macros[macro_name][1]
          msg "  #{@proc.ruby_format(string)}", {:unlimited => true}
        else
          errmsg "%s is not a defined macro" % macro_name
        end
      end
    elsif @proc.macros.empty?
      msg "No macros defined."
    else
      msg columnize_commands(@proc.macros.keys.sort)
    end
  end

end

if __FILE__ == $0
  # Demo it.
  $0 = __FILE__ + 'notagain' # So we don't run this agin
  require_relative '../../mock'
  cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoMacro)
  cmd.run(cmd.prefix + %w(u foo))
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rb8-trepanning-0.1.5 processor/command/info_subcmd/macro.rb
rb8-trepanning-0.1.4 processor/command/info_subcmd/macro.rb
rb8-trepanning-0.1.3 processor/command/info_subcmd/macro.rb
rb8-trepanning-0.1.3-universal-ruby-1.9.2 processor/command/info_subcmd/macro.rb
rb8-trepanning-0.1.3-universal-ruby-1.8.7 processor/command/info_subcmd/macro.rb