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
|
# File 'lib/tainers/cli.rb', line 13
def self.parse parameters
options = {}
options[:spec_source] = from_stdin
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: tainers [opts] COMMAND"
opts.separator ""
opts.separator "Manipulate Tainer-managed containers, taking their specification in JSON (from STDIN by default)."
opts.separator ""
opts.separator "Specific options:"
opts.on('-j JSON', '--json JSON', String, "Take container specification from the given JSON parameter.") do |j|
options[:spec_source] = from_json(j)
end
opts.on('-f FILEPATH', '--file FILEPATH', String, "Take container specification from JSON in the given file.") do |f|
options[:spec_source] = from_file(f)
end
opts.on('-p PREFIX', '--prefix PREFIX', String, "Use PREFIX as container name prefix (overriding whatever is in spec)") do |p|
options['prefix'] = p
end
opts.on('-s SUFFIX', '--suffix SUFFIX', String, "Use SUFFIX as container name suffix (overriding whatever is in spec)") do |s|
options['suffix'] = s
end
opts.on('-h', '--help') do
print opts
exit 0
end
opts.separator ""
opts.separator "Commands:"
Command.commands.each do |name, help|
opts.separator ""
opts.separator " #{name}"
opts.separator " #{help}" if help.size > 0
end
end
non_param = []
args = opt_parser.order(parameters) {|p| non_param << p; opt_parser.terminate}
spec = options.delete(:spec_source).call
spec.update(options)
[spec, non_param + args]
end
|