lib/s3ranger/cli.rb in s3ranger-0.3.0 vs lib/s3ranger/cli.rb in s3ranger-0.3.1
- old
+ new
@@ -60,10 +60,19 @@
u << "[:prefix]"
end
u.join ''
end
+
+ protected
+
+ def parse_acl(opt)
+ @acl = nil
+ opt.on("-a", "--acl=ACL", "Options: #{AVAILABLE_ACLS.join ', '}") {|acl|
+ @acl = acl.to_sym
+ }
+ end
end
class ListBuckets < BaseCmd
def initialize
super 'listbuckets', false, false, false
@@ -84,16 +93,12 @@
def initialize
super 'createbucket', false, false
@short_desc = "Create a new bucket under your user account"
- @acl = nil
-
self.options = CmdParse::OptionParserWrapper.new do |opt|
- opt.on("-a", "--acl=ACL", "Options: #{AVAILABLE_ACLS.join ', '}") {|acl|
- @acl = acl.to_sym
- }
+ parse_acl(opt)
end
end
def run s3, bucket, key, file, args
raise WrongUsage.new(nil, "You need to inform a bucket") if not bucket
@@ -104,11 +109,11 @@
raise WrongUsage.new(nil, "Invalid ACL `#{@acl}'. Should be any of #{AVAILABLE_ACLS.join ', '}") if not AVAILABLE_ACLS.include? @acl
params.merge!({:acl => @acl})
end
s3.buckets.create bucket, params
- rescue AWS::S3::Errors::BucketAlreadyExists => exc
+ rescue AWS::S3::Errors::BucketAlreadyExists
raise FailureFeedback.new("Bucket `#{bucket}' already exists")
end
end
end
@@ -173,11 +178,11 @@
raise WrongUsage.new(nil, "You need to inform a bucket") if not bucket
collection = s3.buckets[bucket].objects.with_prefix(key || "")
if @max_entries > 0
- collection = collection.page(:per_page => max = @max_entries)
+ collection = collection.page(:per_page => @max_entries)
end
collection.each {|object|
o = []
o << object.key
@@ -234,11 +239,11 @@
@secure = false
}
opt.on("--expires-in=EXPR", "How long the link takes to expire. Format: <# of seconds> | [#d|#h|#m|#s]") { |expr|
val = 0
- expr.scan /(\d+\w)/ do |track|
+ expr.scan(/(\d+\w)/) do |track|
_, num, what = /(\d+)(\w)/.match(track[0]).to_a
num = num.to_i
case what
when "d"; val += num * 86400
@@ -262,14 +267,14 @@
opts = {}
opts.merge!({:secure => @secure})
if @public
- puts (s3.buckets[bucket].objects[key].public_url opts).to_s
+ puts s3.buckets[bucket].objects[key].public_url(opts).to_s
else
opts.merge!({:expires => @expires_in}) if @expires_in
- puts (s3.buckets[bucket].objects[key].url_for method.to_sym, opts).to_s
+ puts s3.buckets[bucket].objects[key].url_for(method.to_sym, opts).to_s
end
end
end
class Put < BaseCmd
@@ -315,10 +320,11 @@
attr_accessor :s3
attr_accessor :exclude
attr_accessor :keep
attr_accessor :dry_run
attr_accessor :verbose
+ attr_accessor :acl
def initialize
super 'sync', false, false
@short_desc = "Synchronize an S3 and a local folder"
@@ -334,9 +340,11 @@
}
opt.on("-k", "--keep", "Keep files even if they don't exist in source") {
@keep = true
}
+
+ parse_acl(opt)
opt.on("-d", "--dry-run", "Do not download or exclude anything, just show what was planned. Implies `verbose`.") {
@dry_run = true
@verbose = true
}