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
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
|
# File 'lib/deployman/app/optionparser.rb', line 5
def self.parse (args)
options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: deployman [option1] param1,param2 [optionN] paramN ...\r\n\r\n"
options[:install] = false
opts.on('--install OWNER,SOFTWARE,RELEASE,ZIP_URL,DEST', Array, "Install" ) do |setting|
argumentLength = 5
raise OptionParser::MissingArgument if setting.length < argumentLength
raise OptionParser::NeedlessArgument if setting.length > argumentLength
options[:install] = setting
end
options[:uninstall] = false
opts.on('--uninstall PATH', "Uninstall") do |setting|
options[:uninstall] = setting
end
options[:auth] = false
opts.on('--auth USER,PASS', Array, "HTTP Authentication for Github API (works only in combination with --install)") do |setting|
argumentLength = 2
raise OptionParser::MissingArgument if setting.length < argumentLength
raise OptionParser::NeedlessArgument if setting.length > argumentLength
options[:auth] = setting
end
options[:config] = {}
opts.on('--config VALUES', Array, "add custom config values (works only in combination with --install)\n\t\t\t\t\t VALUES = <key>,<value>,<key>,<value>,...") do |setting|
raise OptionParser::MissingArgument if setting.length % 2 != 0
config = {}
setting.each_slice(2) do |key, value|
config.store(key, value)
end
options[:config] = config
end
options[:callback] = false
opts.on('--callback URL', "callbacks status of installation (running/finished/error) + stdout + stderr\n\t\t\t\t\t JSON-Format: { \"status\" => \"running\", \"stdout\" => <STDOUT>, \"stderr\" => <STDERR> }") do |setting|
options[:callback] = setting
end
options[:createfiles_from_api] = {}
opts.on('--createfiles_from_api VALUES', Array, "creates files from given api-urls (works only in combination with --install),\n\t\t\t\t\t VALUES = <api_url1>,<api_url2>,...\n\t\t\t\t\t The api call has to return the file in following json-format:\n\t\t\t\t\t {\"path\":\"path/to/file.txt\",\"content\":\"content of file\"}") do |setting|
options[:createfiles_from_api] = setting
end
opts.on( '-h', '--help', 'Display help screen' ) do
puts opts
puts "\r\n"
exit
end
end
begin
optparse.parse! args
return options
rescue OptionParser::InvalidOption => e
warn "Error! #{e}"
exit
rescue OptionParser::MissingArgument => e
warn "Error! #{e}"
exit
rescue OptionParser::NeedlessArgument => e
warn "Error! #{e}"
exit
end
end
|