public
Description: A command-line client for Amazon Web Services
Homepage: http://rubyforge.org/projects/cliaws
Clone URL: git://github.com/francois/cliaws.git
francois (author)
Sun Apr 13 04:09:49 -0700 2008
commit  85e876a192e52a923dd8f9a3cb11adb46d10da94
tree    569b5e2da4c47abc70ba46c5d61a6aa0b39b632e
parent  27864a460df81a3d7beaaaba99cdcfd9a7cb415f
cliaws / bin / clis3
100644 99 lines (82 sloc) 1.859 kb
1
2
3
4
5
6
7
8
9
10
11
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env ruby
#
# Created on 2008-4-12.
# Copyright (c) 2008. All rights reserved.
 
begin
  require 'rubygems'
rescue LoadError
  # no rubygems to load, so we fail silently
end
 
require "main"
require "cliaws"
 
Main {
  argument("s3_object") do
    required
    argument_required
  end
 
  mode("list") do
    def run
      puts Cliaws.s3.list(params["s3_object"].value)
    end
  end
 
  mode("touch") do
    def run
      Cliaws.s3.put("", params["s3_object"].value)
    end
  end
 
  mode("put") do
    argument("local_file") do
      optional
      argument_required
    end
 
    option("data") do
      optional
      argument_required
    end
 
    def run
      if params["local_file"].given? && params["data"].given? then
        abort "Cannot give both the --data and local_file parameters at the same time"
      elsif !params["local_file"].given? && !params["data"].given? then
        source = STDIN
      elsif params["local_file"].given? then
        source = File.open(params["local_file"].value, "rb")
      else
        source = params["data"].value
      end
 
      Cliaws.s3.put(source, params["s3_object"].value)
    end
  end
 
  mode("rm") do
    def run
      Cliaws.s3.rm(params["s3_object"].value)
    end
  end
 
  mode("cat") do
    def run
      Cliaws.s3.get(params["s3_object"].value, STDOUT)
      puts
    end
  end
 
  mode("get") do
    argument("local_file") do
      argument_required
      optional
    end
 
    def run
      if params["local_file"].given? then
        dest = File.open(params["local_file"].value, "wb")
      else
        dest = STDOUT
      end
 
      Cliaws.s3.get(params["s3_object"].value, dest)
    end
  end
 
  mode("head") do
    def run
      Cliaws.s3.head(params["s3_object"].value)
    end
  end
 
  def run
    abort "Required action argument missing. Run '#{$0} help' for details."
  end
}