Sha256: f004ee7623c1cdeb55cbc7897759f9cfb53d2c29f85d96eae1dd4311ffa8d94f
Contents?: true
Size: 2 KB
Versions: 1
Compression:
Stored size: 2 KB
Contents
#!/usr/bin/ruby require 'optparse' # How many methods / constants to return. THRESHOLD = 5 MAC = !!/darwin/.match(RUBY_PLATFORM) WINDOWS = !!/win/.match(RUBY_PLATFORM) if not MAC def clear_database file = File.join(File.dirname(__FILE__), "lookup.sqlite3") FileUtils.rm(file) if File.exists?(file) end def display_url(result, options={}) # if we're not on mac or windows we default to text output if OPTIONS[:text] or not (MAC || WINDOWS) s = options[:number] ? options[:number].to_s + ". " : "" # if we're a method then show the constant in parans s += "(#{result.constant.name}) " if result.respond_to?(:constant) s += "#{result.name} #{result.url}" puts s elsif MAC `open #{result.url}` elsif WINDOWS `start #{result.url}` end end def display_results(results, search_string) if results.empty? puts "There were no results matching #{search_string}." # if entry # puts "There are no constants that match #{name} and contain #{entry}." # else # puts "There are no constants that match #{name}" # end elsif results.size == 1 display_url(results.first) elsif results.size <= THRESHOLD results.each_with_index do |result, i| display_url(result, :number => i+1) end else puts "Please refine your query, we found #{results.size} results (threshold is #{THRESHOLD})." end end OPTIONS = {} op=OptionParser.new do |opts| opts.banner = "Usage: lookup <constant|method> [method] [OPTIONS]" opts.on("-c", "--clear", "Clear database") do OPTIONS[:clear] = true end opts.on("-t", "--text", "Text only") do OPTIONS[:text] = true end end op.parse! clear_database if OPTIONS[:clear] local_lib=File.join(File.dirname(__FILE__), "../lib/lookup") if File.exists?(local_lib + ".rb") require local_lib else require 'rubygems' require 'lookup' end search_string=ARGV[0..-1].join(" ") if search_string.strip.empty? puts op.help puts else results=APILookup.search(ARGV[0..-1]) display_results(results, search_string) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lookup-0.4.0 | bin/lookup |