Class: PackageCloud::CLI::Entry

Inherits:
Base
  • Object
show all
Defined in:
lib/package_cloud/cli/entry.rb

Instance Method Summary collapse

Instance Method Details

#push(repo, package_file, *package_files) ⇒ Object



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
62
# File 'lib/package_cloud/cli/entry.rb', line 16

def push(repo, package_file, *package_files)
  ARGV.clear # otherwise gets explodes
  package_files << package_file

  exts = package_files.map { |f| f.split(".").last }.uniq

  if package_files.length > 1 && exts.length > 1
    abort("You can't push multiple packages of different types at the same time.\nFor example, use *.deb to push all your debs at once.".red)
  end

  invalid_packages = package_files.select do |f|
    !["gem", "deb", "rpm"].include?(f.split(".").last)
  end

  if invalid_packages.any?
    message = "I don't know how to push these packages:\n\n".red
    invalid_packages.each do |p|
      message << "  #{p}\n"
    end
    message << "\npackage_cloud only supports debs, gems, and rpms.".red
    abort(message)
  end

  if exts.first == "gem" && package_files.length > 1
    answer = get_valid("Are you sure you want to push #{package_files.length} packages? (y/n)") do |s|
      s == "y" || s == "n"
    end

    if answer != "y"
      puts "Aborting...".red
    end
  end

  validator = Validator.new(client)
  dist_id   = validator.distribution_id(repo, package_files, exts.first)

  # strip os/dist
  repo = repo.split("/")[0..1].join("/")

  print "Looking for repository at #{repo}... "
  repo = client.repository(repo)
  print "success!\n"
  package_files.each do |f|
    print "Pushing #{f}... "
    repo.create_package(f, dist_id)
  end
end

#versionObject



66
67
68
# File 'lib/package_cloud/cli/entry.rb', line 66

def version
  puts "package_cloud CLI #{VERSION}\nSee https://packagecloud.io/docs#cli for more details."
end