#!/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 "-a" options[:all] = true end end options[:all] ||= (options.keys & [:class, :method, :module]).empty? coypond = Coypond::CoypondRunner.new($*) results = coypond.search(options) results.each 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