class Rack2Aws::CLI

Public Instance Methods

run() click to toggle source
# File lib/rack2aws.rb, line 102
def run
  program :name, 'rack2aws'
  program :version, Rack2Aws::VERSION
  program :description, 'Teleport your files from Rackspace Cloud Files to AWS S3'
  program :help, 'Author', 'Faissal Elamraoui <amr.faissal@gmail.com>'

  # Show welcome message
  show_welcome()

  global_option('--verbose', 'Explain what is being done') { $verbose = true }

  command :port do |cmd|
    cmd.syntax = 'rack2aws port [options]'
    cmd.description = 'Port files from Rackspace Cloud Files(tm) to AWS S3'

    cmd.option '--container CONTAINER_NAME', String, 'Rackspace Cloud Files container name'
    cmd.option '--bucket BUCKET_NAME', String, 'AWS S3 bucket name'
    cmd.option '--nproc NUM_PROC', Integer, 'Number of processes to fork'
    cmd.option '--public', 'Whether files should be uploaded as public'
    cmd.action do |args, options|
      if options.container.nil?
        options.container = ask('Rackspace Cloud Files container: ')
      end

      if options.bucket.nil?
        options.bucket = ask('AWS S3 bucket: ')
      end

      if options.nproc.nil?
        options.nproc = processor_count()
      end

      if !options.public.nil?
        options.public = if agree(warn("Are you sure you want your files uploaded as public?"))
                           true
                         else
                           nil
                         end
      end

      options.verbose = !options.verbose.nil? ? true : nil

      # Remove all nil values from options' __hash__ table
      options.__hash__.delete_if{ |k,v| v.nil? }

      FileManager.new(options.__hash__).copy
    end
  end
  run!
end