Sha256: d3521b3adfb84d9d5f04e74b11a017cd4ecab3f3ee7a65f8daa778e9b44f453e

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

#!/usr/bin/env ruby

require 'coypond'

def print_help
  puts "Usage:"
  puts "  coypond search_term [options] file1 [file2 [file3 [...]]]"
  puts ""
  puts "Options:"
  puts "  -m search method names"
  puts "  -c search class names"
  puts "  -M search Module names"
  puts "  -a search all available type names (default: true unless another search option was given)"
end

if $*.first == "-h" || $*.first == "--help"
  print_help
  exit(0)
end
options = {:search_term => $*.shift}
while !$*.empty? and $*.first.start_with?("-")
  option = $*.shift
  case option
  when "-r"
    options[:regexp] = true
  when "-i"
    options[:ignore_case] = true
  when "-m"
    options[:method] = true
  when "-c"
    options[:class] = true
  when "-M"
    options[:module] = true
  when "-g"
    options[:gem] = $*.shift
  when "-a"
    options[:all] = true
  end
end

options[:all] ||= (options.keys & [:class, :method, :module]).empty?

def expand(file, pattern=["**"])
  if File.directory?(file)
    return Dir.glob(File.join(file, *pattern, '*.rb') )
  else
    return file
  end
end

files = []
if options[:gem]
  $:.each do |path|
    files += expand(path, ["#{options[:gem]}*", "**"])
  end
else
  files = $*.map {|file| expand(file)}.flatten
end

coypond = Coypond::CoypondRunner.new(files)
coypond.search(options) do |file_name, res|
  unless res.empty?
    puts "#{file_name}:"
    res.each do |dec, location, context|
      puts "  #{location.join(",")}: #{context.strip}"
    end
    puts ""
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coypond-0.2.1 bin/coypond