Skip to content

Commit 9a03eea

Browse files
committed
Add -e option func
1 parent 513cef6 commit 9a03eea

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bucketsync [--help | --env | --dry-run | --no-ignore | --ignore=VALUE] ACCESSKEY
3333
## Options
3434
<pre>
3535
-h, --help show this help message and exit
36-
-e, --env input access key and secret key from '.env' file
36+
-e, --env input access key, secret key, syncdir and bucket name from '.env' file
3737
--dry-run Only show what should be uploaded or downloaded but
3838
don't actually do it. May still perform S3 requests to
3939
get bucket listings and other information though (only
@@ -50,11 +50,19 @@ put your working folder.
5050
S3_ACCESS_KEY = 'AK1234556'
5151
S3_SECRET_KEY = 'DFEWAefwj381012'
5252
</pre>
53+
OR
54+
<pre>
55+
S3_ACCESS_KEY = 'AK1234556'
56+
S3_SECRET_KEY = 'DFEWAefwj381012'
57+
DEPLOY_DIR = './public/'
58+
S3_BUCKET_NAME = 'bucket_name'
59+
</pre>
5360

5461
## Examples
5562

5663
<pre>
5764
bucketsync AK1234556 DFEWAefwj381012 ./public/ sample-bucket
5865
bucketsync -e ./public/ sample-bucket
66+
bucketsync -e
5967
bucketsync --dry-run AK1234556 DFEWAefwj381012 ./public/ sample-bucket
6068
</pre>

bucketsync

+7-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dry_run_help = [
1717

1818
option={}
1919
OptionParser.new do |opt|
20-
opt.on('-e', '--env', "input access key and secret key from '.env' file") {|v| option[:env] = v}
20+
opt.on('-e', '--env', "input access key, secret key, syncdir and bucket name from '.env' file") {|v| option[:env] = v}
2121
opt.on('--dry-run', *dry_run_help) {|v| option[:dry_run] = v}
2222
opt.on('--no-ignore', 'all files are targeted for upload') {|v| option[:no_ignore] = v}
2323
opt.on('--ignore=VALUE', 'set your ignore file') {|v| option[:ignore] = v}
@@ -36,21 +36,15 @@ class Object
3636
end
3737

3838
def read_env env_file
39-
elements = {
40-
'S3_ACCESS_KEY' => '',
41-
'S3_SECRET_KEY' => ''
42-
}
43-
39+
elements = {}
4440
begin
4541
File.open(env_file) do |file|
4642
file.each_line do |line|
4743
rows = line.split('=')
4844
elem = rows.first.try(:strip)
49-
if elements[elem]
50-
value = rows.last.try(:strip)
51-
next unless value
52-
elements[elem] = value.gsub('"', '').gsub('\'', '')
53-
end
45+
value = rows.last.try(:strip)
46+
next unless value
47+
elements[elem] = value.gsub('"', '').gsub('\'', '')
5448
end
5549
end
5650
rescue => e
@@ -69,8 +63,8 @@ if option[:env]
6963
env = read_env('.env')
7064
access_key = env['S3_ACCESS_KEY']
7165
secret_key = env['S3_SECRET_KEY']
72-
upload_dir = ARGV[0]
73-
bucket_name = ARGV[1]
66+
upload_dir = env['DEPLOY_DIR'] || ARGV[0]
67+
bucket_name = env['S3_BUCKET_NAME'] || ARGV[1]
7468
else
7569
if ARGV.length < 4
7670
puts "too few arguments."

0 commit comments

Comments
 (0)