Class: Pod::Command::Nexus::Push

Inherits:
Pod::Command::Nexus show all
Defined in:
lib/cocoapods-nexus/command/nexus/push.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Push

Returns a new instance of Push.



25
26
27
28
29
30
31
# File 'lib/cocoapods-nexus/command/nexus/push.rb', line 25

def initialize(argv)
  @podspec = argv.shift_argument
  @url = argv.option('url')
  @repo = argv.option('repo')
  @artifact = argv.option('artifact')
  super
end

Class Method Details

.optionsObject



17
18
19
20
21
22
23
# File 'lib/cocoapods-nexus/command/nexus/push.rb', line 17

def self.options
  [
    ['--url=url', 'a nexus hostname'],
    ['--repo=repo', 'a nexus repo'],
    ['--artifact=artifact', 'a nexus artifact']
  ].concat(super)
end

Instance Method Details

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cocoapods-nexus/command/nexus/push.rb', line 40

def run
  podspec_path = File.expand_path(@podspec)
  artifact_path = File.expand_path(@artifact) unless @artifact.nil?

  UI.section("开始发布 #{File.basename(@podspec)} -> #{@url}/nexus/#browse/browse:#{@repo}") do
    spec = Specification.from_file(podspec_path)
    artifact_id = spec.attributes_hash['name']
    version = spec.attributes_hash['version']
    group_id = 'Specs'

    if nexus_api.upload_maven_component(artifact_id: artifact_id,
                                        version: version,
                                        group_id: group_id,
                                        podspec: podspec_path,
                                        artifact: artifact_path,
                                        files: [])
      UI.puts "成功发布 #{artifact_id}(#{version})"
    else
      raise Informative, "发布失败 #{artifact_id}(#{version}),请检查~/.netrc文件或#{@repo}类型"
    end
  end
end

#validate!Object



33
34
35
36
37
38
# File 'lib/cocoapods-nexus/command/nexus/push.rb', line 33

def validate!
  super
  help! 'A podspec is required.' unless @podspec && File.exist?(File.expand_path(@podspec))
  help! 'A url is required.' unless @url
  help! 'A repo is required.' unless @repo
end