Class: S3Sync::CLI::DeleteBucket

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCmd

#execute, #has_options?, #has_prefix?, #usage

Constructor Details

#initializeDeleteBucket

Returns a new instance of DeleteBucket.



149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/s3sync/cli.rb', line 149

def initialize
  super 'deletebucket', takes_commands: false #, false

  @short_desc = "Remove a bucket from your account"

  @force = false

  self.options do |opt|
    opt.on("-f", "--force", "Clean the bucket then deletes it") {|f|
      @force = f
    }
  end
end

Instance Attribute Details

#forceObject

Returns the value of attribute force.



147
148
149
# File 'lib/s3sync/cli.rb', line 147

def force
  @force
end

Instance Method Details

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

Raises:



163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/s3sync/cli.rb', line 163

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

  # Getting the bucket
  bucket_obj = s3.bucket(bucket)

  # Do not kill buckets with content unless explicitly asked
  if not @force and bucket_obj.objects.count > 0
    raise FailureFeedback.new("Cowardly refusing to remove non-empty bucket `#{bucket}'. Try with -f.")
  end

  bucket_obj.delete!
end