lhj-tools 0.2.80 → 0.2.82

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b454eb7049b9d1eb7aa422667ecb0193faf3bd3bed2ac0707bedcebd83778ec1
4
- data.tar.gz: f8e8a846074a0e542acdf457c1c6047b329e373e7e4992f2f002d4f9f3b39e25
3
+ metadata.gz: e5cb532b2f91d92e8575f55aa8f46251351fe6cf8497732c9436344d41c3f10b
4
+ data.tar.gz: 9e90fce95487eb3185ffad60b9840cefa94e4defff4dab3355a809ad524acc45
5
5
  SHA512:
6
- metadata.gz: 4a257a6554374ed53561b728c12aa4eeb8a937a71b4fb28a7b0d1a13258ad486ac011ca02cb2e6c4f276fca0a92c8f346c75281c9caa4b995d77900ddfd4cdeb
7
- data.tar.gz: c3b923e52031eaafa39c201cdba5a64cbc5c4a08ad258c18bcd76aed839081bcfb7eb17ba0657aefd776964147cacbdfa17033845658546774a146800739351d
6
+ metadata.gz: 60613b6d94a186e14a6c06d62e46277658c90804b37d3d62185bc94edba554463ef426de55e687e74338c9617ebaaf09342a7ed21eecb14053ae4068f1d4539a
7
+ data.tar.gz: 96297521dbf1c255087ae94accee5f04de60ea533c6bb46c7ca537c0cc7ceee4ea0269c9b6f7df983821cf676006b071e49f044993ee48fb04395383b2934ff1
@@ -45,8 +45,11 @@ module Lhj
45
45
  en_col = @cli.ask('中英对应照csv<<英文>>所在的列, 默认为2: '.yellow, Integer) do |q|
46
46
  q.default = 2
47
47
  end
48
+ quote_char = @cli.ask('引号字符, 默认为": '.yellow, String) do |q|
49
+ q.default = '"'
50
+ end
48
51
  begin
49
- read_csv_file(csv_file, key_col, cn_col, en_col)
52
+ read_csv_file(csv_file, quote_char, key_col, cn_col, en_col)
50
53
  rescue ArgumentError => e
51
54
  puts e.message.red
52
55
  end
@@ -91,15 +94,17 @@ module Lhj
91
94
  File.exist?(dest_file) ? bak_file(dest_file) : dest_file
92
95
  end
93
96
 
94
- def read_csv_file(file, key_c, cn_c, en_c)
97
+ def read_csv_file(file, quote_char, key_c, cn_c, en_c)
95
98
  begin
96
99
  current_row = nil
97
- CSV.foreach(file, quote_char: ',') do |row|
100
+ CSV.foreach(file, quote_char: quote_char) do |row|
98
101
  current_row = row
99
102
  if row.length > 2
100
103
  key = row[key_c]
101
104
  cn_str = row[cn_c]
102
105
  hk_str = row[cn_c]
106
+ cn_str ||= ''
107
+ hk_str ||= ''
103
108
  # cn_str = Lhj::Trans::Helper.instance.trans_zh_cn_str(cn_str) if trans_cn
104
109
  hk_str = Lhj::Trans::Helper.instance.trans_zh_hk_str(hk_str) if hk_str&.length&.positive?
105
110
  @key_map[key] = { key: key, cn: cn_str, hk: hk_str, en: row[en_c] } unless key =~ /[\u4e00-\u9fa5]/
@@ -10,44 +10,45 @@ module Lhj
10
10
  class OSS < Command
11
11
  class Download < OSS
12
12
 
13
- self.arguments = [
14
- CLAide::Argument.new(['--oss_key_file'], false, false)
15
- ]
16
-
17
13
  self.description = <<~DESC
18
14
  OSS下载,下载文件到当前shell的目录\n
19
15
  提示的下载的序号以,号分割多项下载项, 传入开始与结束的序号通过-号连接,可下载多项连接序号的文件\n
20
16
  如 1,5,7-10,12-15 那么下载项为 [1,5,7,8,9,10,12,13,14,15]\n
21
- --oss_key_file oss key文件列表, 通过lhj oss list --save之后生成oss_key.yml文件, 保留需要下载的oss key,指定文件名oss_key.yml\n
22
- 如: --oss_key_file=oss_key.yml
23
17
  DESC
24
18
 
25
- def self.options
26
- [
27
- %w[--oss_key_file 本地下载的oss_key文件]
28
- ]
29
- end
30
-
31
19
  def initialize(argv)
32
20
  @current_path = argv.shift_argument || Dir.pwd
33
21
  @cli = HighLine.new
34
- @oss_key_file = argv.option('oss_key_file')
35
22
  super
36
23
  end
37
24
 
38
25
  def handle
39
- oss_keys = local_oss_keys if @oss_key_file
40
- oss_keys ||= remote_oss_keys
41
- Dir.chdir(@current_path) do
42
- oss_keys.each { |k| download_with_key(k) }
26
+ type = @cli.choose do |m|
27
+ m.prompt = '选择下载方式?'
28
+ m.choice(:remote)
29
+ m.choice(:local)
43
30
  end
31
+ handle_with_local if type == :local
32
+ handle_with_remote if type == :remote
33
+ end
34
+
35
+ def handle_with_local
36
+ @cli.say(HighLine.color('选择本地yaml文件:', :green))
37
+ path = File.join(@current_path, '**', '*.yml')
38
+ yml_file = @cli.choose(*Dir.glob(path))
39
+ oss_keys = YAML.load_file(yml_file) if File.exist?(yml_file)
40
+ handle_with_oss_keys(oss_keys)
41
+ end
42
+
43
+ def handle_with_remote
44
+ oss_keys = remote_oss_keys
45
+ handle_with_oss_keys(oss_keys)
44
46
  end
45
47
 
46
- def local_oss_keys
47
- key_file = File.join(@current_path, @oss_key_file)
48
- oss_keys = []
49
- oss_keys = YAML.load_file(key_file) if File.exist?(key_file)
50
- oss_keys
48
+ def handle_with_oss_keys(oss_keys)
49
+ Dir.chdir(@current_path) do
50
+ oss_keys.each { |k| download_with_key(k) }
51
+ end
51
52
  end
52
53
 
53
54
  def remote_oss_keys
@@ -42,27 +42,37 @@ module Lhj
42
42
  @output_suffix = argv.option('output_suffix')
43
43
  @marker = argv.option('marker')
44
44
  @current_path = argv.shift_argument || Dir.pwd
45
+ @cli = HighLine.new
45
46
  super
46
47
  end
47
48
 
48
49
  def handle
49
50
  list_opts = {}
51
+ if @save
52
+ time = Time.now.strftime('%Y%m%d_%H%M')
53
+ oss_key_file = @cli.ask(HighLine.color('生成OSS_KEY的名称:', :green), String) do |q|
54
+ q.default = "oss_key_#{time}.yml"
55
+ end
56
+ oss_url_file = @cli.ask(HighLine.color('生成OSS_URL的名称:', :green), String) do |q|
57
+ q.default = "oss_url_#{time}.yml"
58
+ end
59
+ end
50
60
  list_opts[:prefix] = @prefix if @prefix
51
61
  list_opts[:marker] = @marker if @marker
52
62
  list_opts[:delimiter] = '/' if @all_folder
53
63
  objects = Lhj::OSS::Helper.instance.list(list_opts)
54
64
  obj_keys = objects.map(&:key).sort { |a, b| a <=> b } unless @all_folder
55
65
  obj_keys = objects.filter { |o| o.is_a?(String) } if @all_folder
56
- save(obj_keys) if @save
66
+ save(obj_keys, oss_key_file, oss_url_file) if @save
57
67
  print(obj_keys) unless @clear
58
68
  end
59
69
 
60
- def save(obj_keys)
70
+ def save(obj_keys, key_file, url_file)
61
71
  obj_urls = obj_keys.sort { |a, b| a.slice(/\..*/) <=> b.slice(/\..*/) }.map { |k| "#{Lhj::OSS::Helper.instance.url_path}/#{k}" }
62
72
  obj_urls = obj_urls.map { |k| "#{k}?#{@output_suffix}" } if @output_suffix
63
73
  FileUtils.chdir(@current_path) do
64
- File.write('oss_key.yml', obj_keys.to_yaml)
65
- File.write('oss_url.yml', obj_urls.to_yaml) unless @all_folder
74
+ File.write(key_file, obj_keys.to_yaml)
75
+ File.write(url_file, obj_urls.to_yaml) unless @all_folder
66
76
  end
67
77
  end
68
78
 
@@ -10,8 +10,7 @@ module Lhj
10
10
  class Upload < OSS
11
11
 
12
12
  self.arguments = [
13
- CLAide::Argument.new('tag', false),
14
- CLAide::Argument.new('oss_key', false)
13
+ CLAide::Argument.new('tag', false)
15
14
  ]
16
15
 
17
16
  self.description = <<~DESC
@@ -19,20 +18,17 @@ module Lhj
19
18
  提示的上传的序号以,号分割多项下载项, 传入开始与结束的序号通过-号连接,可上传多项连接序号的文件\n
20
19
  如 1,5,7-10,12-15 那么下载项为 [1,5,7,8,9,10,12,13,14,15]\n
21
20
  --tag 指定文件的前缀,如--tag=flutter 则文件为flutter/xx
22
- --oss_key 指定oss key重命名默认oss key,默认oss key为文件名, 如--oss_key=aa.txt
23
21
  DESC
24
22
 
25
23
  def self.options
26
24
  [
27
- %w[--tag 标签],
28
- %w[--oss_key 指定oss_key的名称]
25
+ %w[--tag 标签]
29
26
  ]
30
27
  end
31
28
 
32
29
  def initialize(argv)
33
30
  @current_path = argv.shift_argument || Dir.pwd
34
31
  @tag = argv.option('tag')
35
- @oss_key = argv.option('oss_key')
36
32
  @cli = HighLine.new
37
33
  super
38
34
  end
@@ -51,18 +47,24 @@ module Lhj
51
47
  results << file_list[ma[:begin].to_i..ma[:end].to_i] if ma
52
48
  results << file_list[i.to_i] unless ma
53
49
  end
54
- results.flatten.each do |f|
50
+ results = results.flatten
51
+ results.each do |f|
55
52
  file_name = File.basename(f)
53
+ file_name = rename_oss_key(file_name) if results.length == 1
56
54
  puts "上传的文件名:#{file_name}".yellow
57
- upload(f)
55
+ upload(f, file_name)
58
56
  end
59
57
  end
60
58
 
61
59
  private
62
60
 
63
- def upload(file)
64
- file_name = File.basename(file)
65
- file_name = @oss_key if @oss_key
61
+ def rename_oss_key(original_key)
62
+ @cli.ask(HighLine.color('重定义OSS_KEY:', :green), String) do |q|
63
+ q.default = original_key
64
+ end
65
+ end
66
+
67
+ def upload(file, file_name)
66
68
  oss_key = file_name
67
69
  oss_key = "#{@tag}/#{file_name}" if @tag
68
70
  Lhj::OSS::Helper.instance.upload(oss_key, file)
data/lib/lhj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lhj
4
- VERSION = '0.2.80'
4
+ VERSION = '0.2.82'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.80
4
+ version: 0.2.82
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-15 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj