s3link 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/s3link +0 -0
  2. data/lib/s3link.rb +6 -66
  3. metadata +3 -3
data/bin/s3link CHANGED
File without changes
@@ -1,6 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'aws/s3'
3
3
 
4
+ require 'usage'
5
+ require 'command_line_parser'
6
+
4
7
  module S3Link
5
8
  class CmdLineArgsError < RuntimeError; end
6
9
 
@@ -10,10 +13,10 @@ module S3Link
10
13
  end
11
14
 
12
15
  def run_from_cmd_line
13
- begin
14
- parse_cmd_line
16
+ @options = begin
17
+ S3Link::CommandLineParser.new($ARGV).parse
15
18
  rescue CmdLineArgsError
16
- usage
19
+ Usage.new
17
20
  end
18
21
 
19
22
  puts "Establishing Connection" unless @options[:silent]
@@ -27,41 +30,6 @@ module S3Link
27
30
  puts "#{url}"
28
31
  end
29
32
 
30
- def parse_cmd_line
31
- usage if $ARGV.include?("--help") || $ARGV.include?("--help") || $ARGV.length == 0
32
-
33
- @options[:silent] == ! $ARGV.include?("--silent")
34
-
35
- if $ARGV.include?("--access-key")
36
- @options[:access_key] = next_arg_after("--access-key")
37
- end
38
-
39
- if $ARGV.include?("--secret-key")
40
- @options[:access_key] = next_arg_after("--secret-key")
41
- end
42
-
43
- if $ARGV.include?("--bucket")
44
- @options[:bucket] = next_arg_after("--bucket")
45
- end
46
-
47
- if $ARGV.include?("--expires-in")
48
- @options[:expires_in] = next_arg_after("--expires-in")
49
- end
50
-
51
- if $ARGV.include?("--never-expire")
52
- @options[:never_expire] = true
53
- end
54
-
55
- # Last arg has to be filename
56
- @options[:filename] = $ARGV[-1]
57
- end
58
-
59
- def next_arg_after(key)
60
- index = $ARGV.index(key)
61
- raise CmdLineArgsError if $ARGV.length <= index
62
- $ARGV[index + 1]
63
- end
64
-
65
33
  def establish_connection
66
34
  @aws = AWS::S3::Base.establish_connection!(:access_key_id => access_key, :secret_access_key => secret_key)
67
35
  end
@@ -98,34 +66,6 @@ module S3Link
98
66
  {:expires_in => 24 * 60 * 60}
99
67
  end
100
68
  end
101
-
102
- def usage(msg=nil)
103
- puts msg if msg
104
- puts <<-EOF
105
- Uploads a file up to Amazon's S3 Service, and provides a time limited URL to access.
106
-
107
- Several options may be set via environment variables for ease of use.
108
-
109
- Options:
110
- --access-key <key> [ENV: AMAZON_ACCESS_KEY_ID] -- Amazon provided access key
111
- --secret-key <key [ENV: AMAZON_SECRET_ACCESS_KEY] -- Amazon provided secret key
112
- --bucket <name> [ENV: S3LINK_BUCKET_NAME] -- Bucket to store the uploaded file
113
- --expires-in <hours> [default: 24] -- How long the URL is valid for.
114
- --never-expire -- Never expire the URL. If both
115
- expires commands are set,
116
- --expires-in will win.
117
- --silent -- Quiet mode outputs ONLY the url
118
-
119
- NOTE: This tool DOES NOT ever remove files from S3. Manually using the web
120
- interface, or the s3cmd tool to clean out your bucket is advised.
121
-
122
- WARNING: This tool will just silently overwrite a file that is already
123
- present. This is good to replace files with new versions, but bad if it
124
- destroys something. Don't destroy anything please.
125
-
126
- EOF
127
- exit(1)
128
- end
129
69
  end
130
70
  end
131
71
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3link
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Schneider