-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathastrails-safe
executable file
·64 lines (47 loc) · 1.54 KB
/
astrails-safe
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
#!/usr/bin/env ruby
require 'rubygems'
require 'astrails/safe'
include Astrails::Safe
def die(msg)
puts "ERROR: #{msg}"
exit 1
end
def usage
puts <<-END
Usage: astrails-safe [OPTIONS] CONFIG_FILE
Options:
-h, --help This help screen
-v, --verbose be verbose, duh!
-n, --dry-run just pretend, don't do anything.
-L, --local skip S3 and Cloud Files
Note: config file will be created from template if missing
END
exit 1
end
OPTS = [
'-h', '--help',
'-v', '--verbose', '--not-verbose',
'-n', '--dry-run', '--not-dry-run',
'-L', '--local', '--not-local'
]
def main
opts = ARGV & OPTS
args = ARGV - OPTS
usage unless args.first
usage if opts.delete("-h") || opts.delete("--help")
config_file = File.expand_path(args.first)
is_dry = (opts.delete('-n') || opts.delete('--dry-run')) && ! opts.delete('--not-dry-run')
is_verbose = (opts.delete('-v') || opts.delete('--verbose')) && !opts.delete('--not-verbose')
is_local_only = (opts.delete('-L') || opts.delete('--local')) && !opts.delete('--not-local')
unless File.exists?(config_file)
die "Missing configuration file. NOT CREATED! Rerun w/o the -n argument to create a template configuration file." if is_dry
FileUtils.cp File.join(Astrails::Safe::ROOT, "templates", "script.rb"), config_file
die "Created default #{config_file}. Please edit and run again."
end
config = eval(File.read(config_file))
config[:verbose] = is_verbose
config[:dry_run] = is_dry
config[:local_only] = is_local_only
process config
end
main