1、CocoaPods/lib/cocoapods/command/options/repo_update.rb
module Pod
class Command
module Options
# Provides support for commands to skip updating the spec repositories.
# RepoUpdate 提供給 Pod::Command::xxx include的模塊
module RepoUpdate
# 繼續(xù)擴展 Options 模塊
module Options
def options
[
['--no-repo-update', 'Skip running `pod repo update` before install'],
].concat(super)
end
end
# RepoUpdate模塊被include回調(diào)時,包含上面的module Options
def self.included(base)
# puts base
# -------------------------------
# => Pod::Command::Install
# => Pod::Command::Outdated
# => Pod::Command::Update
# -------------------------------
base.extend(Options)
end
# 獲取 --repo-update 開關(guān)bool值,默認(rèn)值為false
def repo_update?(default: false)
if @repo_update.nil?
default
else
@repo_update
end
end
# 獲取claide解析完畢的 --repo-update 開關(guān)bool值
def initialize(argv)
@repo_update = argv.flag?('repo-update')
super
end
end
end
end
end
2、CocoaPods/lib/cocoapods/command/options/project_directory.rb
module Pod
class Command
module Options
# Provides support for commands to take a user-specified `project directory`
# ProjectDirectory 提供給 Pod::Command::xxx include的模塊
module ProjectDirectory
# ---------------------
# 套路同上
# ---------------------
module Options
def options
[
['--project-directory=/project/dir/', 'The path to the root of the project directory'],
].concat(super)
end
end
def self.included(base)
# puts base
# ------------------------------------
# Pod::Command::Install
# Pod::Command::IPC::Podfile
# Pod::Command::IPC::PodfileJSON
# Pod::Command::IPC::Repl
# Pod::Command::Outdated
# Pod::Command::Update
# ------------------------------------
base.extend(Options)
end
def initialize(argv)
if project_directory = argv.option('project-directory')
@project_directory = Pathname.new(project_directory).expand_path
end
config.installation_root = @project_directory
super
end
# 命令行參數(shù)校驗
def validate!
super
# 必須是【目錄】,否則拋異常結(jié)束執(zhí)行
if @project_directory && !@project_directory.directory?
raise Informative, "`#{@project_directory}` is not a valid directory."
end
end
end
end
end
end
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。