Class: Gem::Commands::GrepCommand
- Inherits:
-
QueryCommand
- Object
- QueryCommand
- Gem::Commands::GrepCommand
- Defined in:
- lib/rubygems/commands/grep_command.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
Returns the value of attribute results.
-
#results_only ⇒ Object
Returns the value of attribute results_only.
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
-
#cleanup_tuples(spec_tuples) ⇒ Object
borrowed from query command.
-
#defaults_str ⇒ Object
:nodoc:.
-
#description ⇒ Object
:nodoc:.
- #execute ⇒ Object
-
#initialize ⇒ GrepCommand
constructor
A new instance of GrepCommand.
- #output_query_results(tuples) ⇒ Object
-
#usage ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ GrepCommand
Returns a new instance of GrepCommand.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rubygems/commands/grep_command.rb', line 8 def initialize super 'grep', "Enhances search command by providing extra search options and displaying results as a table" defaults.merge!(:columns=>[:name,:summary,:authors]) add_option('-c', '--columns STRING', 'Gemspec columns/attributes to display per gem') do |value, | [:columns] = GemGrep.parse_input(value).map {|e| e.to_sym} end add_option('-f', '--fields STRING', 'Gemspec fields/attributes to search (only for local gems)') do |value, | GemGrep.grep_fields = [:fields] = GemGrep.parse_input(value) end remove_option '--name-matches' remove_option '-d' remove_option '--versions' end |
Instance Attribute Details
#results ⇒ Object
Returns the value of attribute results.
7 8 9 |
# File 'lib/rubygems/commands/grep_command.rb', line 7 def results @results end |
#results_only ⇒ Object
Returns the value of attribute results_only.
7 8 9 |
# File 'lib/rubygems/commands/grep_command.rb', line 7 def results_only @results_only end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
24 25 26 |
# File 'lib/rubygems/commands/grep_command.rb', line 24 def arguments # :nodoc: "REGEXP regular expression string to search specified gemspec attributes" end |
#cleanup_tuples(spec_tuples) ⇒ Object
borrowed from query command
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rubygems/commands/grep_command.rb', line 57 def cleanup_tuples(spec_tuples) versions = Hash.new { |h,name| h[name] = [] } spec_tuples.each do |spec_tuple, source_uri| versions[spec_tuple.first] << [spec_tuple, source_uri] end versions = versions.sort_by do |(name,_),_| name.downcase end tuples = [:all] ? versions.inject([]) {|t,e| t += e[1]; t } : versions.map {|e| e[1].first } tuples.each {|e| if e.first.length != 4 uri = URI.parse e.last spec = Gem::SpecFetcher.fetcher.fetch_spec e.first, uri e.first.push(spec) end } tuples end |
#defaults_str ⇒ Object
:nodoc:
32 33 34 |
# File 'lib/rubygems/commands/grep_command.rb', line 32 def defaults_str # :nodoc: "--local --columns name,summary,authors --fields name --no-installed" end |
#description ⇒ Object
:nodoc:
36 37 38 39 40 41 |
# File 'lib/rubygems/commands/grep_command.rb', line 36 def description # :nodoc: 'Enhances search command by providing options to search (--fields) and display (--columns) ' + 'gemspec attributes. Results are displayed in an ascii table. Gemspec attributes can be specified '+ 'by the first unique string that it starts with i.e. "su" for "summary". To specify multiple gemspec attributes, delimit ' + "them with commas. Gemspec attributes available to options are: #{GemGrep.valid_gemspec_columns.join(', ')}." end |
#execute ⇒ Object
43 44 45 46 47 48 |
# File 'lib/rubygems/commands/grep_command.rb', line 43 def execute string = get_one_optional_argument [:name] = /#{string}/i Gem.source_index.extend Gem::SuperSearch super end |
#output_query_results(tuples) ⇒ Object
50 51 52 53 54 |
# File 'lib/rubygems/commands/grep_command.rb', line 50 def output_query_results(tuples) @results = cleanup_tuples(tuples).map {|e| e[0][-1]} @results_only ? @results : say(Hirb::Helpers::Table.render(@results, :fields=>[:columns])) end |
#usage ⇒ Object
:nodoc:
28 29 30 |
# File 'lib/rubygems/commands/grep_command.rb', line 28 def usage # :nodoc: "#{program_name} [REGEXP]" end |