Class: S3Sync::CLI::Get

Inherits:
BaseCmd
  • Object
show all
Defined in:
lib/s3sync/cli.rb

Instance Method Summary collapse

Methods inherited from BaseCmd

#execute, #has_options?, #has_prefix?

Constructor Details

#initializeGet

Returns a new instance of Get.



328
329
330
331
332
# File 'lib/s3sync/cli.rb', line 328

def initialize
  super 'get', false, false
  @short_desc = "Retrieve an object and save to the specified file"
  @has_prefix = 'required'
end

Instance Method Details

#run(s3, bucket, key, file, args) ⇒ Object

Raises:



338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/s3sync/cli.rb', line 338

def run s3, bucket, key, file, args
  raise WrongUsage.new(nil, "You need to inform a bucket") if not bucket
  raise WrongUsage.new(nil, "You need to inform a key") if not key
  raise WrongUsage.new(nil, "You need to inform a file") if not file

  # Saving the content to be downloaded to the current directory if the
  # destination is a directory
  path = File.absolute_path file
  path = S3Sync.safe_join [path, File.basename(key)] if File.directory? path
  File.open(path, 'wb') do |f|
    s3.buckets[bucket].objects[key].read do |chunk| f.write(chunk) end
  end
end

#usageObject



334
335
336
# File 'lib/s3sync/cli.rb', line 334

def usage
  "#{super} path/to/local/destination"
end