Class: Pod::Command::Otssource
- Inherits:
-
Pod::Command
- Object
- Pod::Command
- Pod::Command::Otssource
- Defined in:
- lib/cocoapods-otssource/command/otssource.rb
Overview
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.rband update the class to exist in the the Pod::Command::List namespace -
change this class to extend from
Listinstead ofCommand. This tells the plugin system that it is a subcommand oflist. -
edit
lib/cocoapods_plugins.rbto require this file
Class Method Summary collapse
Instance Method Summary collapse
- #add ⇒ Object
- #allClean ⇒ Object
- #clean ⇒ Object
-
#initialize(argv) ⇒ Otssource
constructor
A new instance of Otssource.
- #list ⇒ Object
-
#run ⇒ Object
def validate! super help! ‘A pod name and tag is required.’ unless @pod_name && @tag end.
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
.options ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/cocoapods-otssource/command/otssource.rb', line 32 def self. [ ['--all-clean', '删除所有已经下载的源码, pod otssource --all-clean'], ['--clean', '删除指定下载的源码, pod otssource #podname --clean'], ['--list', '列出所有已经下载的源码, pod otssource --list'] ] end |
Instance Method Details
#add ⇒ Object
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) = {:git => "https://git.jd.com/onethestore/#{@pod_name}.git",:tag => @tag} = Pod::Downloader.() downloader = Pod::Downloader.for_target(target_path,) downloader.download downloader. UI.puts "源码下载成功" end |
#allClean ⇒ Object
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 |
#clean ⇒ Object
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 |
#list ⇒ Object
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 |
#run ⇒ Object
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 |