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

Constructor Details

#initialize(argv) ⇒ Upload

Returns a new instance of Upload.



29
30
31
32
33
34
# File 'lib/lhj/command/oss/upload.rb', line 29

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

Class Method Details

.optionsObject



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

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

Instance Method Details

#runObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/lhj/command/oss/upload.rb', line 36

def run
  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



24
25
26
27
# File 'lib/lhj/command/oss/upload.rb', line 24

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