Class: Gem::Commands::CompareCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
VersionOption
Defined in:
lib/rubygems/commands/compare_command.rb

Instance Method Summary collapse

Constructor Details

#initializeCompareCommand

Returns a new instance of CompareCommand.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
54
55
56
57
58
59
60
61
# File 'lib/rubygems/commands/compare_command.rb', line 8

def initialize
  super 'compare', 'Compare gem\'s versions and generate a report of changes',
    :output => Dir.pwd

  add_option('-a', '--all', 'Show every comparison') do
    options[:log_all] = true
  end

  add_option('-k', '--keep-all', 'Keep downloaded and extracted gem files') do
    options[:keep_all] = true
  end

  add_option('-n', '--no-color', 'Do not colorize output') do
    options[:no_color] = true
  end

  # Speficy the platform using --platform=PLATFORM
  add_platform_option

  add_option('-pPARAM', '--param PARAM', 'Compare only a given gemspec parameter (like "version")') do |param, options|
    options[:param] = param
  end

  add_option('-r', '--runtime', 'Compare only runtime dependencies') do
    options[:param] = 'runtime_dependency'
  end

  add_option('-d', '--development', 'Compare only development dependencies') do
    options[:param] = 'development_dependency'
  end

  add_option('-f', '--files', 'Compare only files for runtime') do
    options[:param] = 'files'
  end

  add_option('-F', '--diff', 'Diff file contents') do
    options[:diff] = true
    options[:param] = 'files'
  end

  add_option('-g', '--gemfiles', 'Compare only Gemfiles') do
    options[:param] = 'gemfiles'
  end

  add_option('-b', '--brief', 'Include only important changes in the report') do
    options[:log_all] = false
    options[:brief] = true
  end

  add_option('-sSOURCES', '--sources SOURCES', 'Use different source URIs for gems (separated by comma)') do |sources, options|
    options[:sources] = sources.split ','
  end

end

Instance Method Details

#argumentsObject

:nodoc:



63
64
65
66
67
68
69
# File 'lib/rubygems/commands/compare_command.rb', line 63

def arguments # :nodoc:
  args = <<-EOF
        GEMNAME               gem name
        VERSION [VERSION ...] list of versions to compare
  EOF
  return args.gsub(/^\s+/, '')
end

#descriptionObject

:nodoc:



71
72
73
74
75
76
77
# File 'lib/rubygems/commands/compare_command.rb', line 71

def description # :nodoc:
  desc = <<-EOF
         gem-compare is a RubyGems plugin that compares versions of the given gem.
         It searches for differences in metadata as well as in files.
  EOF
  return desc.gsub(/^\s+/, '')
end

#executeObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rubygems/commands/compare_command.rb', line 83

def execute
  gem_name = options[:args].shift
  versions = options[:args]

  # No gem specified
  unless gem_name
    raise Gem::CommandLineError,
      "Please specify a gem (e.g. gem compare foo VERSION [VERSION ...])"
  end

  # No versions specified
  if versions.empty?
    raise Gem::CommandLineError,
      "Please specify versions you want to compare (e.g. gem compare foo 0.1.0 0.2.0)"
  end

  comparator = Gem::Comparator.new(options)
  comparator.compare_versions(gem_name, versions)
  comparator.print_results
end

#usageObject

:nodoc:



79
80
81
# File 'lib/rubygems/commands/compare_command.rb', line 79

def usage # :nodoc:
  "#{program_name} GEMNAME VERSION [VERSION ...]"
end