lhj-tools 0.1.98 → 0.1.99

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: 9c1cb1e36ca0a061c4d3e53f5c0af5c0fb43f5c3dbb044fdd512c44f806a585d
4
+ data.tar.gz: 1ea501e7dde6f267da843ba2aa0f304e2ec038d0ed16f9a4b7348988d982ffab
5
5
  SHA512:
6
- metadata.gz: 50666013e9f5d2565f28cb05c040a3b1bf62e838ee5aa5744c275e3ff088e093df15c3b93f75f841adf43821a9410cb7dfd9b0c8b82a19c737e42fc79b0a1e16
7
- data.tar.gz: 0cfaa91c509467b565af33b0d81b9401f6119c9e2babc17b4f8f993c53899a3bbc363b6f4851d744db2a00c607ecba6832a401800c446748d3b3645346843167
6
+ metadata.gz: 04faa27361e9e260282b8ed9eaaec6d11336c7f5b4af80c069fc6f37956a485a178880ce6397aca1452d14fad32a47059b699bed3e6a67b75e98a5e57bc0921a
7
+ data.tar.gz: 6411de6c950b82eafcf5727c57cbd758a6d3350c1682171ba4bc589ad0ddde95b4a53344cf21b03148834af823f35f27bc0ce98585bfb682d744594257aa5ea8
@@ -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,7 +8,8 @@ module Lhj
8
8
 
9
9
  def self.options
10
10
  [
11
- %w[--save 保存文件]
11
+ %w[--save 保存文件],
12
+ %w[--clear 清空控制台输出]
12
13
  ]
13
14
  end
14
15
 
@@ -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
@@ -22,6 +22,7 @@ module Lhj
22
22
  def initialize(argv)
23
23
  @current_path = argv.shift_argument || Dir.pwd
24
24
  @tag = argv.option('tag')
25
+ @oss_key = argv.option('oss_key')
25
26
  @cli = HighLine.new
26
27
  super
27
28
  end
@@ -51,6 +52,7 @@ module Lhj
51
52
 
52
53
  def upload(file)
53
54
  file_name = File.basename(file)
55
+ file_name = @oss_key if @oss_key
54
56
  oss_key = file_name
55
57
  oss_key = "#{@tag}/#{file_name}" if @tag
56
58
  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
@@ -73,13 +73,28 @@ module Lhj
73
73
  @bucket.set_object_acl(key, acl)
74
74
  end
75
75
 
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
76
+ def alc
77
+ @bucket.acl
78
+ end
79
+
80
+ def logging
81
+ @bucket.logging
82
+ end
83
+
84
+ def lifecycle
85
+ @bucket.lifecycle
86
+ end
87
+
88
+ def cors
89
+ @bucket.cors
90
+ end
91
+
92
+ def website
93
+ @bucket.website
94
+ end
95
+
96
+ def referer
97
+ @bucket.referer
83
98
  end
84
99
 
85
100
  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.1.99"
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.1.99
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