class S3Ranger::CLI::CreateBucket

Attributes

acl[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/s3ranger/cli.rb, line 93
def initialize
  super 'createbucket', false, false

  @short_desc = "Create a new bucket under your user account"

  self.options = CmdParse::OptionParserWrapper.new do |opt|
    parse_acl(opt)
  end
end

Public Instance Methods

run(s3, bucket, key, file, args) click to toggle source
# File lib/s3ranger/cli.rb, line 103
def run s3, bucket, key, file, args
  raise WrongUsage.new(nil, "You need to inform a bucket") if not bucket

  begin
    params = {}
    if @acl
      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
    raise FailureFeedback.new("Bucket `#{bucket}' already exists")
  end
end