#!/usr/bin/env ruby $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib') require "s3ranger/exceptions" require "s3ranger/config" require "s3ranger/cli" conf = S3Ranger::Config.new # Time to load config and see if we've got everything we need to cook our salad begin conf.read rescue S3Ranger::NoConfigFound => exc # We can't proceed without having those two vars set if not (conf.has_key? "AWS_ACCESS_KEY_ID" and conf.has_key? "AWS_SECRET_ACCESS_KEY") $stderr.puts "You didn't set up your environment variables :(" $stderr.puts "I tried the following paths:" exc.paths_checked.each {|path| $stderr.puts " * #{path}/s3config.yml"} $stderr.puts "You could try to set the `S3CONF' environment variable." $stderr.puts "Learn how to do that here: https://github.com/clarete/s3ranger" exit end end # Step aside, the star of this show is here. Let's try to create the # environment to run the requested command. And feed the user back if # information needed was not enough begin S3Ranger::CLI::run conf rescue S3Ranger::FailureFeedback => exc $stderr.puts exc.message exit 1 rescue S3Ranger::WrongUsage => exc name = $0.split('/').last $stderr.puts "Error:\n #{exc.msg}\n" if exc.msg exit exc.error_code end