Class: Pindo::Command::Jps::Download
- Inherits:
-
Pindo::Command::Jps
- Object
- CLAide::Command
- Pindo::Command
- Pindo::Command::Jps
- Pindo::Command::Jps::Download
- Defined in:
- lib/pindo/command/jps/download.rb
Constant Summary
Constants inherited from Pindo::Command
DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS
Instance Attribute Summary
Attributes inherited from Pindo::Command
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Download
constructor
A new instance of Download.
- #run ⇒ Object
- #validate! ⇒ Object
Methods inherited from Pindo::Command
command_name, #initialize_options, run, use_cache?
Methods included from Funlog::Mixin
Methods included from Pindoconfig::Mixin
Constructor Details
#initialize(argv) ⇒ Download
Returns a new instance of Download.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pindo/command/jps/download.rb', line 46 def initialize(argv) @options = (argv) @args_login_flag = @options[:login] || false @args_list_flag = @options[:list] || false @args_conf = @options[:conf] @app_version_index = @options[:index] super(argv) @additional_args = argv.remainder! end |
Class Method Details
.option_items ⇒ Object
38 39 40 |
# File 'lib/pindo/command/jps/download.rb', line 38 def self.option_items @option_items ||= Pindo::Options::JPSOptions.select(:login, :list, :conf, :index) end |
.options ⇒ Object
42 43 44 |
# File 'lib/pindo/command/jps/download.rb', line 42 def self. option_items.map(&:to_claide_option).concat(super) end |
Instance Method Details
#run ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 |
# File 'lib/pindo/command/jps/download.rb', line 63 def run PgyerHelper.share_instace.setForeLogin(beforeLogin:@args_login_flag) app_info_obj = PgyerHelper.share_instace.prepare_upload(working_directory:Dir.pwd, conf:@args_conf) if app_info_obj.nil? raise Informative, "未找到 JPS 项目,请检查配置文件或重新选择" end version_item_obj = PgyerHelper.share_instace.get_versioon_history_item(app_info_obj:app_info_obj, list_select_flat:@args_list_flag) if version_item_obj.nil? raise Informative, "没有找到上传记录" end download_url = version_item_obj["cdnUrl"] base_name = [app_info_obj["projectName"], version_item_obj["projectVersion"], version_item_obj["incId"]].join("_") base_name = base_name + File.extname(download_url) # key_proj_name = proj_name.downcase.strip.gsub(/[\s\-_]/, '') base_name = base_name.strip.gsub(/[\s]/, '').downcase file_name = File.join(Dir.pwd, base_name) puts "文件名: #{file_name}" puts "下载中..." # File.binwrite(file_name, FastlaneCore::Helper.open_uri(download_url).read) # 使用选项参数 Funlog.instance.("开始下载...") total_num = 0 total_size = '' char_in = '>' char_out = '_' = '' URI.open(download_url, :content_length_proc => lambda { |total| total_num = total total_size = sprintf("%.2f", 1.00 * total_num / 1024 /1024 ) }, :progress_proc => lambda { |index_num| progress_str = sprintf("%.2f", 100.0 * index_num / total_num ) total_size = sprintf("%.2f", 1.00 * total_num / 1024 /1024 ) index = 40.0 * index_num / total_num = "已下载:#{progress_str}\%【" + (char_in * (index/1).floor).ljust(40.0, char_out) + "】Total: #{total_size} M" Funlog.instance.() }) do |file| File.binwrite(file_name, file.read) end Funlog.instance.() Funlog.instance.("#{file_name} 下载完成!") end |
#validate! ⇒ Object
58 59 60 61 |
# File 'lib/pindo/command/jps/download.rb', line 58 def validate! super end |