lhj-tools 0.1.98 → 0.2.0

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: e2687cb0ea3db9db8cdf54d080b9b75a642bde044762994af8ee68b4b9117bd6
4
- data.tar.gz: f6720ad9be8a1cf1406f8940d2a95a718490e84692a048f798b04690edc32a26
3
+ metadata.gz: bffa0e0d28d2e9c7aa78faecb8d43c884f85ed22da0b852394950f9c8293f996
4
+ data.tar.gz: 356b8db34ea4892193716b8373d782949efd63c9c67728ee3d35ca4328cbdfe7
5
5
  SHA512:
6
- metadata.gz: 50666013e9f5d2565f28cb05c040a3b1bf62e838ee5aa5744c275e3ff088e093df15c3b93f75f841adf43821a9410cb7dfd9b0c8b82a19c737e42fc79b0a1e16
7
- data.tar.gz: 0cfaa91c509467b565af33b0d81b9401f6119c9e2babc17b4f8f993c53899a3bbc363b6f4851d744db2a00c607ecba6832a401800c446748d3b3645346843167
6
+ metadata.gz: 88c98dd157029e0b81860405d834111bfc53b15205d1658740d5ae539ae677f87d0915f0e4e1e0d76888808785a10295dbe451394d45c0322475539c3bf3eb44
7
+ data.tar.gz: d9d846644b97ea113f8dab060db53f566cab4de1e033a44a406cfa7f35f05a2ad95c3ff803f766ca254aa0e3213b537a9f8524f4d6963b14060bafed7b6fdb80
@@ -14,11 +14,8 @@ module Lhj
14
14
 
15
15
  def handle
16
16
  objects = Lhj::OSS::Helper.instance.list
17
- obj_keys = []
18
- objects.each_with_index do |o, i|
19
- obj_keys << o.key
20
- puts "#{i}.#{o.key}".yellow
21
- end
17
+ obj_keys = objects.map(&:key)
18
+ obj_keys.each_with_index { |k, i| puts "#{i}.#{k}".yellow }
22
19
  idx = @cli.ask('请选择删除的key: '.green)
23
20
  idx_arr = idx.split(',').map(&:strip).filter { |v| v.length.positive? }
24
21
  result_keys = []
@@ -28,9 +25,7 @@ module Lhj
28
25
  result_keys << obj_keys[i.to_i] unless ma
29
26
  end
30
27
  oss_keys = result_keys.flatten
31
- oss_keys.each do |oss_key|
32
- puts "删除的key为:#{oss_key}".red
33
- end
28
+ oss_keys.each { |k| puts "删除的key为:#{k}".red }
34
29
  Lhj::OSS::Helper.instance.batch_delete(oss_keys) if oss_keys.length > 0
35
30
  end
36
31
 
@@ -8,19 +8,36 @@ module Lhj
8
8
  class OSS < Command
9
9
  class Download < OSS
10
10
 
11
+ def self.options
12
+ [
13
+ %w[--oss_key_file 本地下载的oss_key文件]
14
+ ]
15
+ end
16
+
11
17
  def initialize(argv)
12
18
  @current_path = argv.shift_argument || Dir.pwd
13
19
  @cli = HighLine.new
20
+ @oss_key_file = argv.option('oss_key_file')
14
21
  super
15
22
  end
16
23
 
17
24
  def handle
18
- objects = Lhj::OSS::Helper.instance.list
19
- obj_keys = []
20
- objects.each_with_index do |o, i|
21
- obj_keys << o.key
22
- puts "#{i}.#{o.key}".yellow
25
+ oss_keys = local_oss_keys if @oss_key_file
26
+ oss_keys ||= remote_oss_keys
27
+ Dir.chdir(@current_path) do
28
+ oss_keys.each { |k| download_with_key(k) }
23
29
  end
30
+ end
31
+
32
+ def local_oss_keys
33
+ key_file = File.join(@current_path, @oss_key_file)
34
+ oss_keys = []
35
+ oss_keys = YAML.load_file(key_file) if File.exist?(key_file)
36
+ oss_keys
37
+ end
38
+
39
+ def remote_oss_keys
40
+ obj_keys = request_oss_keys
24
41
  idx = @cli.ask('请选择下载的序号: '.green)
25
42
  idx_arr = idx.split(',').map(&:strip).filter { |v| v.length.positive? }
26
43
  result_keys = []
@@ -29,9 +46,13 @@ module Lhj
29
46
  result_keys << obj_keys[ma[:begin].to_i..ma[:end].to_i] if ma
30
47
  result_keys << obj_keys[i.to_i] unless ma
31
48
  end
32
- Dir.chdir(@current_path) do
33
- result_keys.flatten.each { |k| download_with_key(k) }
34
- end
49
+ result_keys.flatten
50
+ end
51
+
52
+ def request_oss_keys
53
+ objects = Lhj::OSS::Helper.instance.list
54
+ obj_keys = objects.map(&:key)
55
+ obj_keys.each_with_index { |k, i| puts "#{i}.#{k}".yellow }
35
56
  end
36
57
 
37
58
  def download_with_key(oss_key)
@@ -7,7 +7,25 @@ module Lhj
7
7
  class Info < OSS
8
8
 
9
9
  def handle
10
- Lhj::OSS::Helper.instance.info
10
+ puts '-------base-----------'
11
+ base_info
12
+ puts '-------alc-----------'
13
+ puts Lhj::OSS::Helper.instance.alc
14
+ puts '-------logging-----------'
15
+ puts Lhj::OSS::Helper.instance.logging
16
+ puts '-------lifecycle----------'
17
+ puts Lhj::OSS::Helper.instance.lifecycle
18
+ puts '-------cors-----------'
19
+ puts Lhj::OSS::Helper.instance.cors
20
+ puts '--------website----------'
21
+ puts Lhj::OSS::Helper.instance.website
22
+ puts '--------referer----------'
23
+ puts Lhj::OSS::Helper.instance.referer
24
+ end
25
+
26
+ def base_info
27
+ puts Lhj::OSSConfig.oss_endpoint
28
+ puts Lhj::OSSConfig.oss_bucket
11
29
  end
12
30
  end
13
31
  end
@@ -8,19 +8,27 @@ module Lhj
8
8
 
9
9
  def self.options
10
10
  [
11
- %w[--save 保存文件]
11
+ %w[--save 保存文件],
12
+ %w[--clear 清空控制台输出],
13
+ %w[--prefix 前缀过滤],
14
+ %w[--marker key之后的列表数据]
12
15
  ]
13
16
  end
14
17
 
15
18
  def initialize(argv)
16
19
  @save = argv.flag?('save', false)
17
20
  @clear = argv.flag?('clear', false)
21
+ @prefix = argv.option('prefix')
22
+ @marker = argv.option('marker')
18
23
  @current_path = argv.shift_argument || Dir.pwd
19
24
  super
20
25
  end
21
26
 
22
27
  def handle
23
- objects = Lhj::OSS::Helper.instance.list
28
+ list_opts = {}
29
+ list_opts[:prefix] = @prefix if @prefix
30
+ list_opts[:marker] = @marker if @marker
31
+ objects = Lhj::OSS::Helper.instance.list(list_opts)
24
32
  obj_keys = objects.map(&:key)
25
33
  save(obj_keys) if @save
26
34
  print(obj_keys) unless @clear
@@ -0,0 +1,28 @@
1
+ require 'lhj/helper/oss_helper'
2
+
3
+ # lhj oss update-bucket
4
+ module Lhj
5
+ class Command
6
+ class OSS < Command
7
+ class UpdateBucket < OSS
8
+
9
+ def initialize(argv)
10
+ @cli = HighLine.new
11
+ super
12
+ end
13
+
14
+ def handle
15
+ bucket_list = Lhj::OSSConfig.oss_bucket_list
16
+ return unless bucket_list.length.positive?
17
+
18
+ bucket_list.each_with_index { |k, i| puts "#{i}.#{k['name']}----#{k['location']}".yellow }
19
+ idx = @cli.ask('更新序号: '.green).strip.to_i
20
+ bucket = bucket_list[idx]
21
+ Lhj::OSSConfig.oss_endpoint = "#{bucket['location']}.aliyuncs.com"
22
+ Lhj::OSSConfig.oss_bucket = bucket['name']
23
+ Lhj::OSSConfig.save
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -15,13 +15,15 @@ module Lhj
15
15
 
16
16
  def self.options
17
17
  [
18
- %w[--tag 标签]
18
+ %w[--tag 标签],
19
+ %w[--oss_key 指定oss_key的名称]
19
20
  ]
20
21
  end
21
22
 
22
23
  def initialize(argv)
23
24
  @current_path = argv.shift_argument || Dir.pwd
24
25
  @tag = argv.option('tag')
26
+ @oss_key = argv.option('oss_key')
25
27
  @cli = HighLine.new
26
28
  super
27
29
  end
@@ -51,6 +53,7 @@ module Lhj
51
53
 
52
54
  def upload(file)
53
55
  file_name = File.basename(file)
56
+ file_name = @oss_key if @oss_key
54
57
  oss_key = file_name
55
58
  oss_key = "#{@tag}/#{file_name}" if @tag
56
59
  Lhj::OSS::Helper.instance.upload(oss_key, file)
data/lib/lhj/command.rb CHANGED
@@ -19,6 +19,7 @@ module Lhj
19
19
  require 'lhj/command/oss/list'
20
20
  require 'lhj/command/oss/info'
21
21
  require 'lhj/command/oss/list_bucket'
22
+ require 'lhj/command/oss/update_bucket'
22
23
  require 'lhj/command/oss/download'
23
24
  require 'lhj/command/code/view'
24
25
  require 'lhj/command/code/code_template'
@@ -17,6 +17,10 @@ module Lhj
17
17
  config['oss_endpoint']
18
18
  end
19
19
 
20
+ def self.oss_endpoint=(endpoint)
21
+ config['oss_endpoint'] = endpoint
22
+ end
23
+
20
24
  def self.oss_access_key_id
21
25
  config['oss_access_key_id']
22
26
  end
@@ -29,8 +33,18 @@ module Lhj
29
33
  config['oss_bucket']
30
34
  end
31
35
 
36
+ def self.oss_bucket=(bucket)
37
+ config['oss_bucket'] = bucket
38
+ end
39
+
32
40
  def self.oss_bucket_list
33
41
  config['oss_bucket_list']
34
42
  end
43
+
44
+ def self.save
45
+ file_to_save = File.open(config_file, 'w+')
46
+ YAML.dump(config, file_to_save)
47
+ file_to_save.close
48
+ end
35
49
  end
36
50
  end
@@ -41,8 +41,11 @@ module Lhj
41
41
  @bucket.object_url(key, false)
42
42
  end
43
43
 
44
- def list
45
- @bucket.list_objects
44
+ # @bucket.list_objects({ prefix: 'tool/config' }) 前缀过滤
45
+ # @bucket.list_objects({ marker: 'code/README.md' }) 当前key之前后
46
+ # @bucket.list_objects({ delimiter: '/' }).filter { |o| o.is_a?(String) } 分割符, 获取所有目录结构
47
+ def list(opts = {})
48
+ @bucket.list_objects(opts)
46
49
  end
47
50
 
48
51
  # {bucket.name} #{bucket.location}
@@ -73,13 +76,28 @@ module Lhj
73
76
  @bucket.set_object_acl(key, acl)
74
77
  end
75
78
 
76
- def info
77
- puts @bucket.acl
78
- puts @bucket.logging
79
- puts @bucket.lifecycle
80
- puts @bucket.cors
81
- puts @bucket.website
82
- puts @bucket.referer
79
+ def alc
80
+ @bucket.acl
81
+ end
82
+
83
+ def logging
84
+ @bucket.logging
85
+ end
86
+
87
+ def lifecycle
88
+ @bucket.lifecycle
89
+ end
90
+
91
+ def cors
92
+ @bucket.cors
93
+ end
94
+
95
+ def website
96
+ @bucket.website
97
+ end
98
+
99
+ def referer
100
+ @bucket.referer
83
101
  end
84
102
 
85
103
  def self.instance
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.98"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  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.1.98
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-17 00:00:00.000000000 Z
11
+ date: 2023-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj
@@ -351,6 +351,7 @@ files:
351
351
  - lib/lhj/command/oss/info.rb
352
352
  - lib/lhj/command/oss/list.rb
353
353
  - lib/lhj/command/oss/list_bucket.rb
354
+ - lib/lhj/command/oss/update_bucket.rb
354
355
  - lib/lhj/command/oss/upload.rb
355
356
  - lib/lhj/command/pgyer_upload.rb
356
357
  - lib/lhj/command/refactor_rename.rb