Class: Lhj::Command::OSS::Upload

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

Overview

OSS file upload

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Lhj::Command

#auto_spin, #begin_title, #run, #stop

Constructor Details

#initialize(argv) ⇒ Upload

Returns a new instance of Upload.



31
32
33
34
35
36
37
# File 'lib/lhj/command/oss/upload.rb', line 31

def initialize(argv)
  @current_path = argv.shift_argument || Dir.pwd
  @type = argv.option('type')
  @name = argv.option('name')
  @tag = argv.option('tag')
  super
end

Class Method Details

.optionsObject



18
19
20
21
22
23
24
# File 'lib/lhj/command/oss/upload.rb', line 18

def self.options
  [
    %w[--type 文件类型],
    %w[--name 文件名],
    %w[--tag 标签]
  ]
end

Instance Method Details

#handleObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/lhj/command/oss/upload.rb', line 39

def handle
  Dir.glob("#{@current_path}/*").each do |f|
    file_name = File.basename(f)
    if @name && /#{@name}/ =~ file_name
      upload(f, file_name)
    elsif @type && /#{@type}/ =~ file_name
      upload(f, file_name)
    end
  end
end

#validate!Object



26
27
28
29
# File 'lib/lhj/command/oss/upload.rb', line 26

def validate!
  super
  help! '类型或名字必须输入' unless @name || @type
end