Class: Pindo::Command::Unity::Packpush
- Inherits:
-
Unity
- Object
- Unity
- Pindo::Command::Unity::Packpush
- Defined in:
- lib/pindo/command/unity/packpush.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Packpush
constructor
A new instance of Packpush.
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ Packpush
Returns a new instance of Packpush.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/pindo/command/unity/packpush.rb', line 65 def initialize(argv) @args_nupkg_file = argv.shift_argument @options = (argv) @force_flag = @options[:force] || false nupkg_option = @options[:nupkg] if !nupkg_option.nil? @args_nupkg_file = nupkg_option end if @args_nupkg_file && !@args_nupkg_file.empty? @args_nupkg_file = @args_nupkg_file.strip.gsub(/\"/, '') end super(argv) @additional_args = argv.remainder! end |
Class Method Details
.arguments ⇒ Object
48 49 50 51 52 |
# File 'lib/pindo/command/unity/packpush.rb', line 48 def self.arguments [ CLAide::Argument.new('path/to/package.nupkg', false), ] end |
.option_items ⇒ Object
54 55 56 57 58 59 |
# File 'lib/pindo/command/unity/packpush.rb', line 54 def self.option_items @option_items ||= Pindo::Options::OptionGroup.merge( Pindo::Options::UtilsOptions.select(:nupkg), Pindo::Options::CommonOptions.select(:force) ) end |
.options ⇒ Object
61 62 63 |
# File 'lib/pindo/command/unity/packpush.rb', line 61 def self. option_items.map(&:to_claide_option).concat(super) end |
Instance Method Details
#run ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/pindo/command/unity/packpush.rb', line 83 def run package_dir = Dir.pwd puts "" puts "🚀 上传 Unity Package 到 JPS" puts "" # 如果没有指定文件或文件不存在,则查找 if @args_nupkg_file.nil? || !File.exist?(@args_nupkg_file) # 在当前目录查找 .nupkg 文件 @args_nupkg_file = Pindo::Unity::NugetHelper.find_nupkg_file(package_dir) # 如果没有找到文件,让用户手动输入 # 非交互(--force / PINDO_AUTO_CONFIRM)时不询问,直接进入后续报错,避免 CI 卡住 if !non_interactive? && (@args_nupkg_file.nil? || !File.exist?(@args_nupkg_file)) @args_nupkg_file = ask('需要上传的文件:') || nil if @args_nupkg_file @args_nupkg_file = @args_nupkg_file.strip.gsub(/\\ /, ' ') end end end # 验证文件存在 if @args_nupkg_file.nil? || !File.exist?(@args_nupkg_file) raise Informative, "未找到 .nupkg 文件" end # 从 nuspec 文件或 package.json 获取包信息(用于显示) package_info = get_package_info_for_upload(package_dir) rescue nil # 显示包信息并确认 if package_info && !package_info.empty? puts "📦 包信息:" puts "" puts " 名称: #{package_info['displayName']}" puts " ID: #{package_info['name']}" puts " 版本: #{package_info['version']}" puts " 文件: #{@args_nupkg_file}" puts " 大小: #{sprintf('%.2f', File.size(@args_nupkg_file) / 1024.0 / 1024.0)} MB" else puts "📦 上传文件:" puts "" puts " 文件: #{@args_nupkg_file}" puts " 大小: #{sprintf('%.2f', File.size(@args_nupkg_file) / 1024.0 / 1024.0)} MB" end puts "" # 检查是否需要跳过确认 # 支持两种方式: # 1. --force 参数 # 2. PINDO_AUTO_CONFIRM 环境变量 if non_interactive? if @force_flag puts "🚀 检测到 --force 参数,跳过确认直接上传..." else puts "🚀 检测到 PINDO_AUTO_CONFIRM 环境变量,跳过确认直接上传..." end else # 确认上传 answer = agree("确认上传?(Y/n)") unless answer puts "已取消上传" return end end puts "" # 创建上传任务 upload_task = Pindo::TaskSystem::NugetUploadTask.new( project_path: package_dir, nupkg_file: @args_nupkg_file ) # 执行任务 task_manager = Pindo::TaskSystem::TaskManager.instance task_manager.clear_all task_manager.add_task(upload_task) task_manager.start puts "" Funlog.instance.("上传完成!") puts "" end |