#!/usr/bin/env ruby require 'slop' def opt_description(msgs) ind = ' ' * 22 msgs.inject { |rtn, msg| rtn << "\n#{ind}#{msg}" } end opts = Slop.parse(help: true) do banner "Usage: gem-search gem_name [options]\n" on :s, :sort, opt_description([ 'Sort by name of item.', ' [n]ame (default)', ' [v]er (displayed name: DL(ver))', ' [a]ll (displayed name: DL(all))' ]), :argument => :optional on :v, :version, 'Display the version.' end OPT_SORT = { 'v' => 'version_downloads', 'a' => 'downloads', } puts opts and exit if (ARGV.size == 0) && (!opts.to_hash.values.include?(true)) exit if opts['h'] $:.unshift File.dirname(__FILE__) + '/../lib' require 'gem-search' if opts['v'] puts "gem-search #{Gem::Search::VERSION}" exit end gs = Gem::Search::CLI.new gs.search(ARGV[0], OPT_SORT[opts['sort']])