Class: S3Sync::CLI::BaseCmd

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

Direct Known Subclasses

CreateBucket, Delete, DeleteBucket, Get, List, ListBuckets, Put, Sync, Url

Instance Method Summary collapse

Instance Method Details

#execute(*args) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/s3sync/cli.rb', line 66

def execute(*args)
  # Connecting to amazon
  s3 = Aws::S3::Resource.new(client: Aws::S3::Client.new)

  # From the command line
  key, file = args

  # Parsing the bucket name
  bucket = nil
  bucket, key = key.split(':') if key

  # Running our custom method inside of the command class, taking care
  # of the common errors here, saving duplications in each command;
  begin
    run s3, bucket, key, file, args
  rescue Aws::S3::Errors::SignatureDoesNotMatch, Aws::S3::Errors::InvalidAccessKeyId => e
    raise FailureFeedback.new("Access Denied: #{e.message}")
  rescue Aws::S3::Errors::NoSuchBucket
    raise FailureFeedback.new("There's no bucket named `#{bucket}'")
  rescue Aws::S3::Errors::NoSuchKey
    raise FailureFeedback.new("There's no key named `#{key}' in the bucket `#{bucket}'")
  rescue Aws::S3::Errors::ServiceError => exc
    raise FailureFeedback.new("Error: `#{exc.message}'")
  end
end

#has_options?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/s3sync/cli.rb', line 43

def has_options?
  not options.instance_variables.empty?
end

#has_prefix?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/s3sync/cli.rb', line 47

def has_prefix?
  @has_prefix
end

#usageObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/s3sync/cli.rb', line 51

def usage
  u = []
  u << "Usage: #{File.basename commandparser.program_name} #{name} "
  u << "[options] " if has_options?
  u << "bucket" if has_args?

  if has_prefix? == 'required'
    u << ':prefix'
  elsif has_prefix?
    u << "[:prefix]"
  end

  u.join ''
end