module Pod class Command class JxedtCommand < Command class Binary < JxedtCommand class Clean < Binary self.summary = 'clean cache repo.' self.description = <<-DESC clean cache repo. DESC self.command = 'clean' self.arguments = [ ] def self.options [ ['--name', 'Remove the file with the corresponding name.'], ['--local', 'Remove local cache.'], ['--all', 'Remove all files.'], ] end def initialize(argv) @names = argv.option('name', '').split(',') @local = argv.flag?('local', false) @all = argv.flag?('all', false) super end def validate! help! "Please enter the necessary options." if @names.empty? && !@all super end def run podfile = Pod::Config.instance.podfile help! '请检查命令执行路径,需要在Podfile文件所在目录执行' if podfile.nil? require 'cocoapods-jxedt/git_helper/git_command' repo = Jxedt.config.git_remote_repo cache_path = Jxedt.config.git_cache_path branch = Jxedt.config.cache_branch local_cache_dir = Pod::Config.instance.sandbox.root + Jxedt.config.binary_dir commander = nil commander = Jxedt::GitCommand.new(cache_path) if !@local && Jxedt.config.cache_repo_enabled? # fetch commander.git_fetch(repo, branch) if commander if @names.size > 0 local_deleted, remote_deleted = [], [] @names.each do |name| local_cache = local_cache_dir + name if local_cache.exist? local_cache.rmtree local_deleted << name end if commander remote_cache_dir = Pathname.new(cache_path) + "GeneratedFrameworks" remote_cache = remote_cache_dir + name if remote_cache.exist? remote_cache.rmtree remote_deleted << name end end end # push commander.git_commit_and_push(branch) if commander && remote_deleted.size > 0 UI.puts "⚠️ ⚠️ ⚠️ 本地缓存文件已清除: #{local_deleted}" if local_deleted.size > 0 UI.puts "⚠️ ⚠️ ⚠️ 远程缓存文件已清除: #{remote_deleted}" if remote_deleted.size > 0 else random = (0...10).map { (97 + rand(26)).chr }.join input = get_stdin("你确认要清除所有缓存吗?包括远程仓库的缓存。确认请输入: #{random}") help! "输入错误,自动退出。" if random != input local_cache_dir.rmtree if local_cache_dir.exist? if commander remote_cache_dir = Pathname.new(cache_path) + "GeneratedFrameworks" if remote_cache_dir.exist? remote_cache_dir.rmtree # push commander.git_commit_and_push(branch) end end UI.puts "⚠️ ⚠️ ⚠️ 所有缓存文件已清除" end end def get_stdin(message) UI.puts "#{message}".red print "请输入--> ".green val = STDIN.gets.chomp.strip val end end end end end end