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
|
# File 'lib/ath/cli.rb', line 6
def parse_options
options = {
database: 'default',
output_location: ENV['ATH_OUTPUT_LOCATION'],
pager: ENV['ATH_PAGER'],
debug: false,
}
query = nil
query_file = nil
@argv.options do |opt|
aws_opts = {}
creds_opts = {}
begin
opt.on('-p', '--profile PROFILE_NAME') {|v| creds_opts[:profile_name] = v }
opt.on('' , '--credentials-path PATH') {|v| creds_opts[:path] = v }
opt.on('-k', '--access-key ACCESS_KEY') {|v| aws_opts[:access_key] = v }
opt.on('-s', '--secret-key SECRET_KEY') {|v| aws_opts[:secret_access_key] = v }
opt.on('-r', '--region REGION') {|v| aws_opts[:region] = v }
opt.on('' , '--output-location S3URI') {|v| options[:output_location] = v }
opt.on('-d', '--database DATABASE') {|v| options[:database] = v }
opt.on('-e', '--execute QUERY') {|v| query = v }
opt.on('-f', '--file QUERY_FILE') {|v| query_file = v }
opt.on('', '--pager PAGER') {|v| options[:pager] = v }
opt.on('', '--[no-]progress') {|v| options[:progress] = v }
opt.on('' , '--debug') { options[:debug] = true }
opt.parse!
unless options[:output_location]
raise Ath::Error, '"--output-location" or ATH_OUTPUT_LOCATION is required'
end
if not creds_opts.empty?
creds = Aws::SharedCredentials.new(credentials_opts)
aws_opts[:credentials] = creds
end
Aws.config.update(aws_opts)
rescue Ath::Error, OptionParser::ParseError => e
$stderr.puts("[ERROR] #{e.message}")
exit 1
rescue => e
$stderr.puts("[ERROR] #{e.message}")
puts "\t" + e.backtrace.join("\n\t")
exit 1
end
end
if options[:debug]
Aws.config.update(
http_wire_trace: true,
logger: Logger.new($stdout).tap {|l| l.level = Logger::DEBUG },
)
end
begin
options[:output_location] = ERB.new(options[:output_location]).result
rescue => e
$stderr.puts("[ERROR] Eval output-location failed: #{e.message}")
exit 1
end
return [options, query, query_file]
end
|