Class: Lhj::Command::OSS::UpdateBucket

Inherits:
Lhj::Command::OSS show all
Defined in:
lib/lhj/command/oss/update_bucket.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Lhj::Command

#auto_spin, #begin_title, #run, #stop

Constructor Details

#initialize(argv) ⇒ UpdateBucket

Returns a new instance of UpdateBucket.



15
16
17
18
19
# File 'lib/lhj/command/oss/update_bucket.rb', line 15

def initialize(argv)
  @cli = HighLine.new
  @idx = argv.option('idx')
  super
end

Class Method Details

.optionsObject



9
10
11
12
13
# File 'lib/lhj/command/oss/update_bucket.rb', line 9

def self.options
  [
    %w[--idx 最新bucket序号]
  ]
end

Instance Method Details

#handleObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lhj/command/oss/update_bucket.rb', line 21

def handle
  bucket_list = Lhj::OSSConfig.oss_bucket_list
  return unless bucket_list.length.positive?

  bucket_list.each_with_index { |k, i| puts "#{i}.#{k['name']}----#{k['location']}".yellow }
  idx = @idx.to_i if @idx
  idx = @cli.ask('更新序号: '.green).strip.to_i unless @idx
  bucket = bucket_list[idx]
  puts "update: #{bucket['name']} -- #{bucket['location']}"
  Lhj::OSSConfig.oss_endpoint = "#{bucket['location']}.aliyuncs.com"
  Lhj::OSSConfig.oss_bucket = bucket['name']
  Lhj::OSSConfig.oss_domain = bucket['domain']
  Lhj::OSSConfig.save
end