lib/s3sync/cli.rb in s3sync-2.0.0 vs lib/s3sync/cli.rb in s3sync-2.0.1

- old
+ new

@@ -61,10 +61,36 @@ end u.join '' end + def execute(args) + # Connecting to amazon + s3 = AWS::S3.new + + # From the command line + key, file = args + + # Parsing the bucket name + bucket = nil + bucket, key = key.split(':') if key + + # Running our custom method inside of the command class, taking care + # of the common errors here, saving duplications in each command; + begin + run s3, bucket, key, file, args + rescue AWS::S3::Errors::AccessDenied + raise FailureFeedback.new("Access Denied") + rescue AWS::S3::Errors::NoSuchBucket + raise FailureFeedback.new("There's no bucket named `#{bucket}'") + rescue AWS::S3::Errors::NoSuchKey + raise FailureFeedback.new("There's no key named `#{key}' in the bucket `#{bucket}'") + rescue AWS::S3::Errors::Base => exc + raise FailureFeedback.new("Error: `#{exc.message}'") + end + end + protected def parse_acl(opt) @acl = nil opt.on("-a", "--acl=ACL", "Options: #{AVAILABLE_ACLS.join ', '}") {|acl| @@ -430,43 +456,10 @@ # Built-in commands cmd.add_command CmdParse::HelpCommand.new cmd.add_command CmdParse::VersionCommand.new - # Defining the `execute` method as a closure, so we can forward the - # arguments needed to run the instance of the chosen command. - CmdParse::Command.class_eval do - define_method :execute, lambda { |args| - - # Connecting to amazon - s3 = AWS::S3.new( - :access_key_id => conf[:AWS_ACCESS_KEY_ID], - :secret_access_key => conf[:AWS_SECRET_ACCESS_KEY], - ) - - # From the command line - key, file = args - - # Parsing the bucket name - bucket = nil - bucket, key = key.split(':') if key - - # Running our custom method inside of the command class, taking care - # of the common errors here, saving duplications in each command; - begin - run s3, bucket, key, file, args - rescue AWS::S3::Errors::AccessDenied - raise FailureFeedback.new("Access Denied") - rescue AWS::S3::Errors::NoSuchBucket - raise FailureFeedback.new("There's no bucket named `#{bucket}'") - rescue AWS::S3::Errors::NoSuchKey - raise FailureFeedback.new("There's no key named `#{key}' in the bucket `#{bucket}'") - rescue AWS::S3::Errors::Base => exc - raise FailureFeedback.new("Error: `#{exc.message}'") - end - } - end - + # Boom! Execute it cmd.parse end module_function :run