Class: Gem::Commands::InfoCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/rubygems_plugin.rb

Instance Method Summary collapse

Constructor Details

#initializeInfoCommand

Returns a new instance of InfoCommand.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubygems_plugin.rb', line 9

def initialize
  super 'info', "Print information about a gem.  Fuzzy matching available."
  add_option('-1', '--exactly-one', "Fail if not exactly 1 match.") do |value, options|
    options[:exactly_one] = true
  end
  add_option('-f', '--format STRING', "Format of output (see below).") do |value, options|
    options[:format] = value
  end
  add_option('-N', '--no-newlines', "Suppress printing of newlines after each gem") do |value, options|
    options[:no_newlines] = true
  end
end

Instance Method Details

#argumentsObject



22
23
24
25
26
27
# File 'lib/rubygems_plugin.rb', line 22

def arguments
  <<-EOS.gsub(/^ *\|/, '')
    |NAME     (fuzzy) name of the gem
    |VERSION  (fuzzy) version of the gem
  EOS
end

#default_strObject



33
34
35
# File 'lib/rubygems_plugin.rb', line 33

def default_str
  ''
end

#descriptionObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rubygems_plugin.rb', line 37

def description
  <<-EOS.gsub(/^ *\|/, '')
    |Print information about matching gems.  The NAME and
    |VERSION are fuzzy-matched according to the following
    |algorithm:
    |
    | * Look for gems exactly matching NAME.
    | * If none found, look for gems containing NAME. e.g.,
    |   "inf" matches "gem_info"
    | * If none found, look for gems containing the characters
    |   of NAME in the same order.  e.g, "e_nf" matches
    |   "gem_info"
    | * Filter the results above with the version string in the
    |   same way.
    |
    |The format string (--format option) has the following
    |escapes available:
    |
    |%rubygems_version
    |  Rubygems version that built the gemspec
    |%specification_version
    |  Version of the gem's gemspec
    |%name
    |  Gem name
    |%version
    |  Gem version
    |%date
    |%date[STRFTIME_FORMAT]
    |  Date the gem was released. STRFTIME_FORMAT may contain
    |  any %-escapes honored by Time#strftime
    |%summary
    |  Summary of the gem
    |%email
    |  Email address of the gem author
    |%homepage
    |  Homepage of the gem
    |%rubyforge_project
    |  Name of the rubyforge project
    |%description
    |  Gem description
    |%executables
    |  List of executables (comma separated)
    |%bindir
    |  Directory the gem's executables are installed into
    |%required_ruby_version
    |  Ruby version required for the gem
    |%required_rubygems_version
    |  Rubygems version required for the gem
    |%platform
    |  Platform the gem is built for
    |%signing_key
    |  Key which signed the gem
    |%cert_chain
    |  Certificate chain used for signing ("\\n\\n" separated)
    |%post_install_message
    |  Message displayed upon installation
    |%authors
    |  List of author names (comma separated)
    |%licenses
    |  List of license names (comma separated)
    |%dependencies
    |  List of dependencies (comma separated)
    |%path
    |  Path of the installed gem
    |%%
    |  A '%' character
    |%N
    |  A newline
  EOS
end

#executeObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/rubygems_plugin.rb', line 108

def execute
  begin
    GemInfo::Runner.run(options, *options[:args])
  rescue GemInfo::UsageError
    STDERR.puts "USAGE: #{usage}"
    terminate_interaction(1)
  rescue GemInfo::Error => e
    STDERR.puts e.message
    terminate_interaction(1)
  rescue Object => e
    puts "Unexpected error!  Debug with DEBUG=1"
    if ENV['DEBUG']
      STDERR.puts "#{exception.class}: #{exception.message}"
      exception.backtrace.each do |line|
        STDERR.puts "  #{line}"
      end
    end
    raise
  end
end

#usageObject



29
30
31
# File 'lib/rubygems_plugin.rb', line 29

def usage
  "#{program_name} NAME [VERSION]"
end