Class: Stickler::Client::LatestVersion

Inherits:
Stickler::Client show all
Defined in:
lib/stickler/client/latest-version.rb

Instance Attribute Summary

Attributes inherited from Stickler::Client

#argv, #sources

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Stickler::Client

config, #initialize, #parser, #remote_repo_for

Constructor Details

This class inherits a constructor from Stickler::Client

Class Method Details



4
5
6
7
8
9
10
11
12
# File 'lib/stickler/client/latest-version.rb', line 4

def self.banner
  <<-_
Prints the latest version of a gem

Usage: stickler latest-version gem-name

  Options:
_
end

Instance Method Details

#parse(argv) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/stickler/client/latest-version.rb', line 14

def parse( argv )
  gem_name = nil
  opts = super( argv ) do |p,o|
    raise Trollop::CommandlineError, "At lest one gem-name is required" if p.leftovers.empty?
    gem_name = p.leftovers.shift
  end
  opts[:gem_name] = gem_name
  return opts
end

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stickler/client/latest-version.rb', line 24

def run
  opts  = parse( self.argv )
  repo  = remote_repo_for( opts )
  match = repo.latest_specs_list.find do |name, version, platform|
    name == opts[:gem_name]
  end
  if match then
    $stdout.puts match[1]
  else
    $stdout.puts "Gem #{opts[:gem_name]} not found in remote repository"
  end
rescue Stickler::Repository::Error => e
  $stdout.puts "ERROR: #{e.message}"
end