Class: Lhj::Command::OSS::Del

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

Instance Method Summary collapse

Methods inherited from Lhj::Command

#auto_spin, #begin_title, #run, #stop

Constructor Details

#initialize(argv) ⇒ Del

Returns a new instance of Del.



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

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

Instance Method Details

#handleObject



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

def handle
  objects = Lhj::OSS::Helper.instance.list
  obj_keys = objects.map(&:key).sort { |a, b| a <=> b }
  obj_keys.each_with_index { |k, i| puts "#{i}.#{k}".yellow }
  idx = @cli.ask('请选择删除的key: '.green)
  idx_arr = idx.split(',').map(&:strip).filter { |v| v.length.positive? }
  result_keys = []
  idx_arr.each do |i|
    ma = /(?<begin>[0-9]*)\D*-\D*(?<end>[0-9]*)/.match(i)
    result_keys << obj_keys[ma[:begin].to_i..ma[:end].to_i] if ma
    result_keys << obj_keys[i.to_i] unless ma
  end
  oss_keys = result_keys.flatten
  oss_keys.each { |k| puts "删除的key为:#{k}".red }
  Lhj::OSS::Helper.instance.batch_delete(oss_keys) if oss_keys.length > 0
end