Module: RightPublish::CLI

Defined in:
lib/right_publish/cli.rb

Constant Summary collapse

REPOSITORY_TYPES =
RepoManager.repo_types()
SUB_COMMANDS =
%w(publish pull add annotate push)

Class Method Summary collapse

Class Method Details

.expand_argv_globsObject



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

def self.expand_argv_globs
  files = []

  ARGV.each do |glob|
    files += Dir.glob(glob)
  end

  files
end

.parse_argsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/right_publish/cli.rb', line 48

def self.parse_args()
  options = Trollop.options do
    version "RightPublish (c) 2013 RightScale Inc"
    banner <<-EOS
RightPublish can manage a YUM/APT/RubyGem repository in remote storage, e.g. S3.

Usage:
   right_publish [options] <command> [file1, file2, ...]

basic commands:
  publish

advanced commands:
  pull add annotate push

options:
    EOS

    opt :local_cache,       "Local cache location", :type => String
    opt :profile,           "Publish profile", :type => String, :default => nil
    opt :repo_type,         "Repository type: #{REPOSITORY_TYPES.keys.inspect}", :type => String
    opt :dist,              "Target distribution. Required for binary packages. If unspecified for noarch and source packages, will copy to all distributions specified in profile.", :type => String
    opt :verbose,           "Verbose output"
  end

  options[:cmd]= ARGV.shift
  options[:files] = expand_argv_globs

  Trollop.die "invalid repository type: #{options[:repo_type]}" unless REPOSITORY_TYPES[options[:repo_type]]

  options
end

.runObject



8
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
44
45
46
# File 'lib/right_publish/cli.rb', line 8

def self.run()
  options = parse_args

  begin
    profile = RightPublish::Profile.instance
    profile.load(options[:profile] || options[:repo_type])
  rescue LoadError => e
    puts e
    exit -1
  end

  # These options override profile attributes.
  profile.settings[:local_storage][:cache_dir] = options[:local_cache] if options[:local_cache]
  profile.settings[:verbose] = true if options[:verbose]

  # We already know this is a valid type, parse_args checked
  repo = RepoManager.get_repository(REPOSITORY_TYPES[options[:repo_type]])
  begin
    case options[:cmd]
    when 'publish'
      repo.publish(options[:files], options[:dist])
    when 'pull'
      repo.pull
    when 'add'
      repo.add(options[:files], options[:dist])
    when 'annotate'
      repo.annotate
    when 'push'
      repo.push
    else
      raise ArgumentError, "Unknown command '#{options[:cmd]}'"
    end
  rescue RuntimeError => e
    RightPublish::Profile.log("Fatal Error:\n\t#{e}", :error)
    exit -1
  end

  exit 0
end