Class: S3Ranger::CLI::DeleteBucket

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeleteBucket

Returns a new instance of DeleteBucket.



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/s3ranger/cli.rb', line 65

def initialize
  super 'deletebucket', false, false

  @short_desc = "Remove a bucket from your account"

  @force = false

  self.options = CmdParse::OptionParserWrapper.new 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.



63
64
65
# File 'lib/s3ranger/cli.rb', line 63

def force
  @force
end

Instance Method Details

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

Raises:



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/s3ranger/cli.rb', line 79

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.buckets[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