Class: S3aps::Runner
- Inherits:
-
Object
- Object
- S3aps::Runner
- Defined in:
- lib/s3aps/runner.rb
Overview
Allows you to run S3aps from the command line
Instance Attribute Summary collapse
-
#argv ⇒ Object
Returns the value of attribute argv.
Instance Method Summary collapse
-
#help ⇒ Object
:nodoc:.
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
-
#list ⇒ Object
Prints out a list of all remote and local files and shows which ones are remote, local or both.
-
#pull ⇒ Object
Pull files from S3.
-
#push ⇒ Object
Push files to S3.
-
#run ⇒ Object
:nodoc:.
-
#sync(options) ⇒ Object
:nodoc:.
-
#version ⇒ Object
:nodoc:.
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/s3aps/runner.rb', line 12 def initialize(argv) @options = {} @cmd = :help @option_parser = OptionParser.new do |o| o. = <<EOS S3aps version #{S3aps::VERSION} Usage: s3aps (list|pull|push|version) [OPTIONS] list List files locally and remotely pull Pull new files from remote push Push new files to remote (be careful) EOS o.on("-c", "--config FILE", "YAML file containing S3 credentials") {|name| @options[:config] = name } o.on("-e", "--env ENV", "Section of YAML to use") {|name| @options[:env] = name } o.on("-b", "--bucket NAME", "S3 bucket name") {|name| @options[:bucket] = name } o.on("-k", "--key KEY", "S3 access key") {|name| @options[:key] = name } o.on("-s", "--secret KEY", "S3 secret key") {|name| @options[:secret] = name } o.on("-p", "--path PATH", "Local path") {|name| @options[:path] = name } o.parse!(argv) end if argv.size == 1 && %w(list push pull version).include?(argv.first) @sync = S3aps::Sync.new @options @cmd = argv.first end end |
Instance Attribute Details
#argv ⇒ Object
Returns the value of attribute argv.
10 11 12 |
# File 'lib/s3aps/runner.rb', line 10 def argv @argv end |
Instance Method Details
#help ⇒ Object
:nodoc:
43 44 45 |
# File 'lib/s3aps/runner.rb', line 43 def help #:nodoc: puts @option_parser.help end |
#list ⇒ Object
Prints out a list of all remote and local files and shows which ones are remote, local or both.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/s3aps/runner.rb', line 53 def list array = @sync.list local_count = 0 remote_count = 0 array.each do |item| line = item.join(' ') local_count +=1 if line =~ /^L\s\s/ remote_count +=1 if line =~ /^\s\sR/ puts item.join(' ') end puts "Found #{array.size} file(s): #{local_count} local only, #{remote_count} remote only, #{array.size - local_count - remote_count} common." end |
#pull ⇒ Object
Pull files from S3
67 68 69 70 |
# File 'lib/s3aps/runner.rb', line 67 def pull count, total = @sync.pull puts "\nPulled #{count}/#{total} file#{'s' unless count == 1} from S3" end |
#push ⇒ Object
Push files to S3
73 74 75 76 |
# File 'lib/s3aps/runner.rb', line 73 def push count, total = @sync.push puts "\nPushed #{count} file#{'s' unless count == 1} to S3" end |
#run ⇒ Object
:nodoc:
39 40 41 |
# File 'lib/s3aps/runner.rb', line 39 def run #:nodoc: send(@cmd) end |