Class: PackageCloud::CLI

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

Instance Method Summary collapse

Instance Method Details

#create(repo_name) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/package_cloud/cli.rb', line 51

def create(repo_name)
  config.read_or_create
  client = Client.new(config)

  print "Looking for repository at #{repo_name}... "
  repo = client.create_repo(repo_name, options[:private])
  print "success!\n".green
  puts "Your repository has been created at:"
  puts "    #{repo["url"]}"
end

#install(repo, package_type) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/package_cloud/cli.rb', line 81

def install(repo, package_type)
  if Process.uid != 0 && package_type != "gem"
    abort("You have to run install as root.".red)
  end

  print "Locating repository at #{repo}... "
  repo = client.repository(repo)
  print "success!\n"
  pid = fork { exec(repo.install_script(package_type)) }
  Process.waitpid(pid)
end

#list ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/package_cloud/cli.rb', line 64

def list
  repos = client.repositories
  if repos.length == 0
    puts "You have no repositories at the moment. Create one!"
  else
    puts "Your repositories:"
    puts ""
    repos.each_with_index do |repo, i|
      puts "  #{repo.fqname} (#{repo.private_human})"
      puts "  last push: #{repo.last_push_human} | packages: #{repo.package_count_human}"
      puts "" unless i == repos.length - 1
    end
  end
end

#list_distros(package_type) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/package_cloud/cli.rb', line 11

def list_distros(package_type)
  distros = client.distributions[package_type]
  if distros
    puts "Listing distributions for #{package_type}:"
    distros.each do |distro|
      puts "\n    #{distro["display_name"]} (#{distro["index_name"]}):\n\n"
      distro["versions"].each do |ver|
        puts "        #{ver["display_name"]} (#{ver["index_name"]})"
      end
    end

    puts "\nIf you don't see your distribution or version here, email us at [email protected]."
  else
    puts "No distributions exist for #{package_type}.".red
    puts "That either means that we don't support #{package_type} or that it doesn't require a distribution/version."
    exit(1)
  end
end

#push(repo, package_file) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/package_cloud/cli.rb', line 32

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

  validator = Validator.new(client)
  dist_id   = validator.distribution_id(repo, package_file)

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

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