Class: Gem::Commands::ReadmeCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
VersionOption, GemToolbox::CommonOptions
Defined in:
lib/rubygems/commands/readme_command.rb

Overview

ReadmeCommand opens the gem’s readme file using $PAGER or $GEM_PAGER

Instance Method Summary collapse

Methods included from GemToolbox::CommonOptions

#add_command_option, #add_exact_match_option, #add_latest_version_option, #get_path, #get_spec, #show

Constructor Details

#initializeReadmeCommand

Returns a new instance of ReadmeCommand.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rubygems/commands/readme_command.rb', line 8

def initialize
  super "readme", "Show gem's readme file using $GEM_PAGER or $PAGER",
    :command => nil, 
    :version => Gem::Requirement.default,
    :latest  => false
  
  add_latest_version_option
  add_exact_match_option
  add_version_option
  add_command_option
end

Instance Method Details

#argumentsObject

:nodoc:



20
21
22
# File 'lib/rubygems/commands/readme_command.rb', line 20

def arguments # :nodoc:
  "GEMNAME      Gem to show readme for"
end

#executeObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubygems/commands/readme_command.rb', line 24

def execute
  name = get_one_optional_argument
  path = get_path(name)
  
  if path
    if file = find_readme(path)
      show file
    else
      say "No readme found for #{name}"
    end
  end
end

#find_readme(path) ⇒ Object



37
38
39
# File 'lib/rubygems/commands/readme_command.rb', line 37

def find_readme(path)
  Dir.glob(File.join(path, "{README,readme,Readme,ReadMe}*")).first
end