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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
# File 'lib/wombat/cli.rb', line 19
def self.parse(args)
options = OpenStruct.new
global = OptionParser.new do |opts|
opts.banner = "Usage: #{NAME} [SUBCOMMAND [options]]"
opts.separator ""
opts.version = Wombat::VERSION
opts.separator <<-COMMANDS.gsub(/^ {8}/, "")
build : build one or more templates
delete : delete a stack
deploy : deploy a stack
help : prints this help message
init : create wombat skeleton project
list : list all templates in project
outputs : get outputs for a stack
latest : search for latest images
update : update lock and/or cloud template
COMMANDS
end
templates_argv_proc = proc { |options|
options.templates = ARGV unless args.empty?
}
box_version_argv_proc = proc { |options|
options.box = ARGV[0]
options.version = ARGV[1]
}
stack_argv_proc = proc { |options|
options.stack = ARGV[0]
}
file_argv_proc = proc { |options|
options.file = ARGV[0]
}
subcommand = {
build: {
class: BuildRunner,
parser: OptionParser.new { |opts|
opts.banner = "Usage: #{NAME} build [options] TEMPLATE[ TEMPLATE ...]"
opts.on("-o BUILDER", "--only BUILDER", 'Only build the builds with the given comma-separated names') do |opt|
options.builder = opt
end
opts.on("--parallel", "Build in parallel") do |opt|
options.parallel = opt
end
opts.on("-c CONFIG", "--config CONFIG", "Specify a different yaml config (default is wombat.yml)") do |opt|
options.wombat_yml = opt
end
opts.on("--debug", "Run in debug mode.") do |opt|
options.debug = opt
end
opts.on("--novendorcookbooks", "Do not vendor cookbooks") do |opt|
options.vendor = opt
end
},
argv: templates_argv_proc
},
delete: {
class: DeleteRunner,
parser: OptionParser.new { |opts|
opts.banner = "Usage: #{NAME} delete STACK"
opts.on("-c CLOUD", "--cloud CLOUD", "Select cloud") do |opt|
options.cloud = opt
end
opts.on("--force", "Force the removal of the parent resource group") do |opt|
options.force = opt
end
opts.on("--async", "Delete resources asynchronously when not removing all, e.g. do not block command line. (Azure Only)") do |opt|
options.azure_async = opt
end
opts.on("--config CONFIG", "Specify a different yaml config (default is wombat.yml)") do |opt|
options.wombat_yml = opt
end
},
argv: stack_argv_proc
},
deploy: {
class: DeployRunner,
parser: OptionParser.new { |opts|
opts.banner = "Usage: #{NAME} deploy STACK"
opts.on("-c CLOUD", "--cloud CLOUD", "Select cloud") do |opt|
options.cloud = opt
end
opts.on("--update-lock", "Update lockfile") do |opt|
options.update_lock = opt
end
opts.on("--update-template", "Update template") do |opt|
options.update_template = opt
end
opts.on("--async", "Deploy stack asynchronously, e.g. do not block command line. Only applies to Azure deployments.") do |opt|
options.azure_async = opt
end
opts.on("--config CONFIG", "Specify a different yaml config (default is wombat.yml)") do |opt|
options.wombat_yml = opt
end
opts.on("-n NAME", "--name NAME", "Name of the stack to create rather than the filename of the stack. Implies --nosuffix.") do |opt|
options.stack_name = opt
end
opts.on("--nosuffix", "Do not append timestamp to end of the stack (Azure Only)") do |opt|
options.nosuffix = opt
end
},
argv: stack_argv_proc
},
help: {
parser: OptionParser.new {},
argv: proc { |options|
puts global
exit(0)
}
},
init: {
class: InitRunner,
parser: OptionParser.new { |opts|
opts.banner = "Usage: #{NAME} init"
opts.on("-p PATH", "--path PATH", "Path to copy skeleton") do |opt|
options.path = opt
end
},
argv: stack_argv_proc
},
list: {
class: ListRunner,
parser: OptionParser.new { |opts|
opts.banner = "Usage: #{NAME} list [TEMPLATE ...]"
},
argv: templates_argv_proc
},
outputs: {
class: OutputRunner,
parser: OptionParser.new { |opts|
opts.banner = "Usage: #{NAME} outputs STACK"
opts.on("-c CLOUD", "--cloud CLOUD", "Select cloud") do |opt|
options.cloud = opt
end
},
argv: stack_argv_proc
},
latest: {
class: LatestRunner,
parser: OptionParser.new { |opts|
opts.banner = "Usage: #{NAME} search"
opts.on("-c CLOUD", "--cloud CLOUD", "Select cloud") do |opt|
options.cloud = opt
end
},
argv: stack_argv_proc
},
update: {
class: UpdateRunner,
parser: OptionParser.new { |opts|
opts.banner = "Usage: #{NAME} update [lock || template]"
opts.on("-c CLOUD", "--cloud CLOUD", "Select cloud") do |opt|
options.cloud = opt
end
opts.on("--config CONFIG", "Specify a different yaml config (default is wombat.yml)") do |opt|
options.wombat_yml = opt
end
},
argv: file_argv_proc
}
}
global.order!
command = args.empty? ? :help : ARGV.shift.to_sym
subcommand.fetch(command).fetch(:parser).order!
subcommand.fetch(command).fetch(:argv).call(options)
options.command = command
options.klass = subcommand.fetch(command).fetch(:class)
options
end
|