Class: Stickler::Client::Push

Inherits:
Stickler::Client show all
Defined in:
lib/stickler/client/push.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



5
6
7
8
9
10
11
12
13
# File 'lib/stickler/client/push.rb', line 5

def self.banner
<<-_
Push one or more gems to a gemserver.

Usage: stickler push [options] gemfile(s)

  Options:
_
end

Instance Method Details

#parse(argv) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/stickler/client/push.rb', line 15

def parse( argv )
  gemfiles = []
  opts = super do |p,o|
    raise Trollop::CommandlineError, "At least one file is required to push" if p.leftovers.empty?
    p.leftovers.each do |gemfile|
      raise Trollop::CommandlineError, "#{gemfile} must be readable" unless File.readable?( gemfile )
      gemfiles << File.expand_path( gemfile )
    end
  end
  opts[:gemfiles] = gemfiles
  return opts
end

#runObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/stickler/client/push.rb', line 28

def run
  opts = parse( self.argv )
  repo = remote_repo_for( opts )

  width = opts[:gemfiles].collect { |g| g.length }.sort.last

  $stdout.puts "Pushing gem(s) to #{repo.uri} ..."
  opts[:gemfiles].each do |gemfile|
    begin
      $stdout.write "  #{gemfile.ljust( width )} -> "
      $stdout.flush
      spec = repo.push( gemfile )
      ok_msg = "OK"
      ok_msg += " #{repo.uri_for_gem( spec )}"
      $stdout.puts ok_msg
    rescue Stickler::Repository::Error => e
      $stdout.puts "ERROR: #{e.message}"
    end
  end
end