1、cocoapods/lib/cocoapods/command/setup.rb
require 'fileutils' # ruby系统库
module Pod
class Command
class Setup < Command
# 1、基本描述
self.summary = 'Setup the CocoaPods environment'
self.description = <<-DESC
Creates a directory at `~/.cocoapods/repos` which will hold your spec-repos.
This is where it will create a clone of the public `master` spec-repo from:
https://github.com/CocoaPods/Specs
If the clone already exists, it will ensure that it is up-to-date.
DESC
# 2、拷贝调用外部git可执行程序的代码
# 已经在 cocoapods/lib/cocoapods/command.rb 文件中,
# 执行 require 'cocoapods/command/setup' 符号导入,
# 所以再次扩展打开 class Command 时,可以直接使用 cocoapods/command/setup.rb
extend Executable # cocoapods/lib/cocoapods/executable.rb
executable :git # executable(:git) 生成调用git可执行程序的操作
# 3、claide解析完命令行参数的回调处理
def run
# 3.1、提示:Setting up CocoaPods master repo...
UI.section 'Setting up CocoaPods master repo' do
if master_repo_dir.exist? # master repo dir 存在
set_master_repo_url # set_master_repo_url()
set_master_repo_branch # set_master_repo_branch()
update_master_repo # update_master_repo()
else # master repo dir 不存在
add_master_repo # add_master_repo()
end
end
# 3.2、提示:Setup completed
UI.puts 'Setup completed'.green
end
#--------------------------------------#
# @!group Setup steps
# Sets the url of the master repo according to whether it is push.
#
# @return [void]
#
def set_master_repo_url
Dir.chdir(master_repo_dir) do
git('remote', 'set-url', 'origin', url)
# git('remote', 'set-url', 'origin', url())
# => git remote set-url origin 'https://github.com/CocoaPods/Specs.git'
end
end
# Adds the master repo from the remote.
#
# @return [void]
#
def add_master_repo
cmd = ['master', url, 'master', '--progress']
# cmd = ['master', url(), 'master', '--progress']
# cocoapods-1.5.3/lib/cocoapods/command/repo/add.rb
# /Users/xiongzenghui/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/cocoapods-1.5.3/lib/cocoapods/command/repo/add.rb
# 同样已经在 cocoapods/lib/cocoapods/command.rb 文件中,
# 执行 require 'cocoapods/command/setup' 导入,
# 执行 require 'cocoapods/command/repo' 符号导入
Repo::Add.parse(cmd).run
end
# Updates the master repo against the remote.
#
# @return [void]
#
def update_master_repo
show_output = !config.silent?
config.sources_manager.update('master', show_output) # 更新 master pod repo
end
# Sets the repo to the master branch.
#
# @note This is not needed anymore as it was used for CocoaPods 0.6
# release candidates.
#
# @return [void]
#
def set_master_repo_branch
Dir.chdir(master_repo_dir) do
git %w(checkout master) # git checkout master
end
end
#--------------------------------------#
# @!group Private helpers
# @return [String] the url to use according to whether push mode should
# be enabled.
#
def url
self.class.read_only_url # return 'https://github.com/CocoaPods/Specs.git'
end
# @return [String] the read only url of the master repo.
#
def self.read_only_url
'https://github.com/CocoaPods/Specs.git'
end
# @return [Pathname] the directory of the master repo.
#
def master_repo_dir
config.sources_manager.master_repo_dir
end
end
end
end
2、pod setup 干的事情
-
1、master pod repo 不存在
- 1)add_master_repo()
-
2、master pod repo 存在
- 1)set_master_repo_url()
- 2)set_master_repo_branch()
- 3)update_master_repo()
网友评论