Class: Ploy::Command::List

Inherits:
Base
  • Object
show all
Defined in:
lib/ploy/command/list.rb

Instance Method Summary collapse

Instance Method Details

#helpObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ploy/command/list.rb', line 45

def help
  return "usage: ploy -b BUCKET [-d DEPLOYMENT -B BRANCH]\n\n\#{optparser}\n\nExamples:\n  $ ploy list -b deploybucket\n\nSummary\n\n  The list command lists published packages, their current sha, and\n  their current blessed sha. (By default it only lists packages where\n  blessed is not current.)\n"
end

#run(argv) ⇒ Object



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
# File 'lib/ploy/command/list.rb', line 9

def run(argv)
  o = {:branch => 'master', :all => false, :json => false, :deploy => nil}
  optparser(o).parse!(argv)
  #puts o.to_yaml

  bucket = o[:bucket]
  branch = o[:branch]

  packages = []
  if o[:deploy].nil?
    store = Ploy::S3Storage.new(bucket)
    packages = store.list
  else
    packages = [o[:deploy]]
  end

  packages.each do |name|
    current = Ploy::Package.new(bucket, name, branch, 'current').remote_version
    blessed_current = Ploy::Package.new(bucket, name, branch, 'current', 'blessed').remote_version

    if o[:all] || current != blessed_current
      if o[:json]
        h = { name => {
          'name'        => name,
          'sha'         => current,
          'branch'      => branch,
          'blessed_sha' => blessed_current
        } }
        puts h.to_json
      else
        puts "#{name} #{branch} #{current} #{blessed_current}"
      end 
    end
  end
end