Class: Gem::Commands::ChangelogCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::ChangelogCommand
- Defined in:
- lib/rubygems/commands/changelog_command.rb
Instance Method Summary collapse
- #arguments ⇒ Object
- #execute ⇒ Object
- #find_changelog_file(spec) ⇒ Object
-
#initialize ⇒ ChangelogCommand
constructor
A new instance of ChangelogCommand.
- #show_first_lines(file_path, number = 10) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ ChangelogCommand
Returns a new instance of ChangelogCommand.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rubygems/commands/changelog_command.rb', line 7 def initialize super 'changelog', 'Show the changelog of given gem' add_option '-f CHANGELOG_NAME', 'Specify name of the changelog file' do |v| [:changelog_name] = v end add_option '-v VERSION', 'Specify version' do |v| [:version_requirement] = v end add_option '-n', '--lines=LINES', 'Show the first LINES lines of the changelog' do |v| raise OptionParser::InvalidArgument, v unless v =~ OptionParser::DecimalInteger [:lines] = v.to_i end end |
Instance Method Details
#arguments ⇒ Object
59 60 61 |
# File 'lib/rubygems/commands/changelog_command.rb', line 59 def arguments 'GEM_NAME name of the gem to show' end |
#execute ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubygems/commands/changelog_command.rb', line 22 def execute args = [:args] gem_name = args.first unless gem_name show_help terminate_interaction 1 end version_requirement = [:version_requirement] || '>=0.pre' spec = find_spec(gem_name, version_requirement) changelog_file = [:changelog_name] || find_changelog_file(spec) unless changelog_file if files(spec.gem_dir).empty? say('Changelog file could not be found.') else say('Changelog file could not be found. Try -f option with one of following file(s).') files(spec.gem_dir).each do |file| say('- %s' % file) end end terminate_interaction 1 end changelog_path = File.join(spec.gem_dir, changelog_file) if [:lines] show_first_lines(changelog_path, [:lines]) else system(pager, changelog_path) end end |
#find_changelog_file(spec) ⇒ Object
63 64 65 |
# File 'lib/rubygems/commands/changelog_command.rb', line 63 def find_changelog_file(spec) files(spec.gem_dir).sort.find {|file| CHANGELOG_RE === file } end |
#show_first_lines(file_path, number = 10) ⇒ Object
67 68 69 70 71 |
# File 'lib/rubygems/commands/changelog_command.rb', line 67 def show_first_lines(file_path, number=10) open file_path do |file| puts file.each_line.take(number) end end |
#usage ⇒ Object
55 56 57 |
# File 'lib/rubygems/commands/changelog_command.rb', line 55 def usage "#{program_name} GEM_NAME" end |