Class: Pod::Command::Otssource

Inherits:
Pod::Command show all
Defined in:
lib/cocoapods-otssource/command/otssource.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) ⇒ Otssource

Returns a new instance of Otssource.



40
41
42
43
44
45
46
47
48
# File 'lib/cocoapods-otssource/command/otssource.rb', line 40

def initialize(argv)
  @pod_name = argv.shift_argument
  @tag = argv.shift_argument

  @list = argv.flag?('list', false )
  @all_clean = argv.flag?('all-clean', false )
  @clean = argv.flag?('clean', false )
  super
end

Class Method Details

.optionsObject



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

def self.options
  [
    ['--all-clean', '删除所有已经下载的源码, pod otssource --all-clean'],
    ['--clean', '删除指定下载的源码, pod otssource #podname --clean'],
    ['--list', '列出所有已经下载的源码, pod otssource --list']
  ]
end

Instance Method Details

#addObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cocoapods-otssource/command/otssource.rb', line 70

def add
  if @pod_name == nil or @tag == nil
    help! 'A pod name and tag is required.'
    return
  end

  UI.puts "开始下载源码#{@pod_name}-#{@tag}"

  target_path = "/var/tmp/iBiu_release/#{@pod_name}/App-Lint"
  FileUtils.rm_rf(target_path)
  options = {:git => "https://git.jd.com/onethestore/#{@pod_name}.git",:tag => @tag}
  options = Pod::Downloader.preprocess_options(options)
  downloader = Pod::Downloader.for_target(target_path,options)
  downloader.download
  downloader.checkout_options

  UI.puts "源码下载成功"
end

#allCleanObject



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/cocoapods-otssource/command/otssource.rb', line 118

def allClean
  Dir::chdir("/var/tmp/iBiu_release/")
  current_dir = Dir::getwd
  Dir::entries("/var/tmp/iBiu_release/").each do |sub|
    unless sub.eql?("App-Lint") or sub.eql?(".") or sub.eql?("..")
      full_path = File.join(current_dir,sub)
      FileUtils.rm_rf(full_path) if File.directory?(full_path)            
    end
  end
  UI.puts "所有源码已删除"
end

#cleanObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cocoapods-otssource/command/otssource.rb', line 89

def clean
  if @pod_name == nil
    help! 'A pod name required. pod otssource #podname --clean'
    return
  end
  Dir::chdir("/var/tmp/iBiu_release/")
  current_dir = Dir::getwd
  Dir::entries("/var/tmp/iBiu_release/").each do |sub|
    full_path = File.join(current_dir,@pod_name)
    if File.directory?(full_path)
      FileUtils.rm_rf(full_path)
      UI.puts "#{@pod_name}已删除"
      break
    end
  end
end

#listObject



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/cocoapods-otssource/command/otssource.rb', line 106

def list
  UI.puts "列出所有已经下载的源码:"
  Dir::chdir("/var/tmp/iBiu_release/")
  current_dir = Dir::getwd
  Dir::entries("/var/tmp/iBiu_release/").each do |sub|
    unless sub.eql?("App-Lint") or sub.eql?(".") or sub.eql?("..")
      full_path = File.join(current_dir,sub)
      UI.puts "#{sub}" if File.directory?(full_path)            
    end
  end
end

#runObject

def validate!

super
help! 'A pod name and tag is required.' unless @pod_name && @tag

end



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cocoapods-otssource/command/otssource.rb', line 55

def run
  if @list
    list
  elsif @all_clean
    allClean
  elsif @pod_name
    if @clean
      clean
    else
      add
    end
  end
  
end