Class: Ploy::Command::List

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

Instance Method Summary collapse

Instance Method Details

#generate_list(bucket, packages, branch, variant, json, all) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ploy/command/list.rb', line 21

def generate_list(bucket, packages, branch, variant, json, all)
  packages.each_with_object([]) do |name, collection|
    current = Ploy::Package.new(bucket, name, branch, 'current').remote_version
    blessed_current = Ploy::Package.new(bucket, name, branch, 'current', variant).remote_version

    next unless all || current != blessed_current

    if json
      collection << json_package(name, branch, current, blessed_current)
    else
      collection << "#{name} #{branch} #{current} #{blessed_current}"
    end
  end
end

#helpObject



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

def help
  return <<helptext
usage: ploy -b BUCKET [-d DEPLOYMENT -B BRANCH]

#{optparser}

Examples:
  $ ploy list -b deploybucket

Summary

  The list command lists published packages, their current sha, and
  their current blessed sha. (By default it only lists packages where
  blessed is not current.)
helptext
end

#json_package(package, branch, current, blessed_current) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/ploy/command/list.rb', line 36

def json_package(package, branch, current, blessed_current)
  {
    package => {
      'name'        => package,
      'sha'         => current,
      'branch'      => branch,
      'blessed_sha' => blessed_current
    }
  }.to_json
end

#run(argv) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/ploy/command/list.rb', line 10

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

  packages = o[:deploy].nil? ? Ploy::S3Storage.new(o[:bucket]).list : [o[:deploy]]
  
  generate_list(o[:bucket], packages, o[:branch], o[:variant], o[:json], o[:all]).each do |package|
    puts package
  end
end