Class: Pod::Command::Marstransfer

Inherits:
Pod::Command show all
Defined in:
lib/cocoapods-marstransfer/command/marstransfer.rb

Overview

TODO:

Create a PR to add your plugin to CocoaPods/cocoapods.org in the ‘plugins.json` file, once your plugin is released.

This is an example of a cocoapods plugin adding a top-level subcommand to the ‘pod’ command.

You can also create subcommands of existing or new commands. Say you wanted to add a subcommand to ‘list` to show newly deprecated pods, (e.g. `pod list deprecated`), there are a few things that would need to change.

  • move this file to ‘lib/pod/command/list/deprecated.rb` and update the class to exist in the the Pod::Command::List namespace

  • change this class to extend from ‘List` instead of `Command`. This tells the plugin system that it is a subcommand of `list`.

  • edit ‘lib/cocoapods_plugins.rb` to require this file

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Marstransfer

Returns a new instance of Marstransfer.



43
44
45
46
47
48
49
50
51
52
# File 'lib/cocoapods-marstransfer/command/marstransfer.rb', line 43

def initialize(argv)
  @lockfile = argv.shift_argument
  @pod_repo = argv.option('pod_repo', '')
  @tos_domain = argv.option('tos_domain', '')
  @tos_key = argv.option('tos_key', '')
  @tos_bucket = argv.option('tos_bucket', '')
  @trans_ve = argv.flag?('trans_ve',false)

  super
end

Class Method Details

.optionsObject



33
34
35
36
37
38
39
40
41
# File 'lib/cocoapods-marstransfer/command/marstransfer.rb', line 33

def self.options
  options = [
    ['--pod_repo=pod_repo',    'the repo name of local cocoapods source'],
    ['--tos_domain=tos_domain',    'the domain from tos service'],
    ['--tos_key=tos_key',    'the key from tos service'],
    ['--tos_bucket=tos_bucket',    'the bucket from tos service'],
    ['--trans_ve',    'transfer volc engine'],
  ]
end

Instance Method Details

#make_working_dirObject



96
97
98
99
# File 'lib/cocoapods-marstransfer/command/marstransfer.rb', line 96

def make_working_dir
  Dir.mkdir 'source' unless Dir.exist?('source')
  Dir.mkdir 'podspec' unless Dir.exist?('podspec')
end

#runObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cocoapods-marstransfer/command/marstransfer.rb', line 59

def run
  temp_dir = ""
  Dir.mktmpdir("marstransfer") do |dir|
    puts "[MARS] working dir: #{dir}"
    lockfile = Pod::Lockfile.from_file(Pathname.new(@lockfile))
    pod_names = lockfile.pod_names
    pods_by_spec_repo = lockfile.pods_by_spec_repo
    puts "[MARS] pods_by_spec_repo: #{pods_by_spec_repo}"
    trunk_pods = pods_by_spec_repo["trunk"]
    if trunk_pods.nil? 
      trunk_pods = pods_by_spec_repo["https://cdn.cocoapods.org/"]
    end 

    ve_pods = []
    if @trans_ve
      ve_pods = pods_by_spec_repo["https://github.com/volcengine/volcengine-specs.git"]
    end

    Dir.chdir(dir) do
      make_working_dir
      if trunk_pods.length > 0
        pod_specs = trunk_pods.map do |pod|
          transfer = Transfer.new(lockfile,@pod_repo,@tos_key,@tos_domain,@tos_bucket)
          if @tos_domain.include?("byted.org")
            transfer.transfer_pod_tos(pod)
          else
            transfer.transfer_demo()
            transfer.transfer_pod(pod)
          end
        end
      end
    end
    temp_dir = dir
  end
  FileUtils.rm_rf(temp_dir)
end

#validate!Object



54
55
56
57
# File 'lib/cocoapods-marstransfer/command/marstransfer.rb', line 54

def validate!
  super
  help! 'A lockfile is required.' unless @lockfile
end