Class: S3Ranger::CLI::CreateBucket

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCmd

#has_options?, #has_prefix?, #usage

Constructor Details

#initializeCreateBucket

Returns a new instance of CreateBucket.



93
94
95
96
97
98
99
100
101
# 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

Instance Attribute Details

#aclObject

Returns the value of attribute acl.



91
92
93
# File 'lib/s3ranger/cli.rb', line 91

def acl
  @acl
end

Instance Method Details

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

Raises:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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