-
Notifications
You must be signed in to change notification settings - Fork 44
/
toolkit.rb
executable file
·67 lines (58 loc) · 1.7 KB
/
toolkit.rb
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
#!/usr/bin/env ruby
# frozen_string_literal: true
# all dependencies
require_relative "lib/toolkit"
require_relative "lib/params_helper"
# First split up whatever we got
args_array = Kenna::Toolkit::ParamsHelper.build_params(ARGV) # FIXME: This mangles AWS ARNs
args = {}
# Parse TOOLKIT prefixed environment variables into arg hash
ENV.each do |k, v|
args[k.split("_", 2).last.to_sym] = v if (k.start_with? "TOOLKIT") && !v.empty?
end
# Then split up this into a hash
args_array.each do |arg|
name_value = arg.split("=", 2)
arg_name = name_value[0].to_sym
arg_value = name_value[1]
# handle a request for just "help" as a special case
if arg_name == :help
print_usage
exit
end
# make sure all arguments were well formed
unless arg_name && arg_value
if arg == "aws"
print_error "Because toolkit can separate task options with colons, you must wrap ARNs"
print_error %q(in escaped double quotes like: my_arn="\"arn:aws:ec2:foo:123/bar\"")
else
print_error "FATAL! Invalid Argument: #{arg}"
print_error "All arguments should take the form [name]=[value]"
print_error "Multiple arguments should be separated by colons (:) or spaces"
end
exit 1
end
# set the arg value into the hash
args[arg_name] = arg_value
end
# Fail if we didnt get a task
unless args[:task]
print_error "FATAL! Missing required argument: 'task'"
print_usage
exit 1
end
# handle task request
case args[:task]
when "help"
print_usage
exit
else
task_class = Kenna::Toolkit::TaskManager.find_by_id((args[:task]).to_s.strip)
if task_class
puts "Running: #{task_class}"
task_class.new.run(args)
else
puts "[!] Error. Unknown task requested!"
exit 1
end
end