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
|
# File 'lib/puppet_languageserver_sidecar.rb', line 104
def self.parse(options)
args = {
action: nil,
action_parameters: PuppetLanguageServer::Sidecar::Protocol::ActionParams.new,
debug: nil,
disable_cache: false,
flags: [],
output: nil,
puppet_settings: [],
puppet_version: nil,
workspace: nil
}
opt_parser = OptionParser.new do |opts|
opts.banner = 'Usage: puppet-languageserver-sidecar.rb [options]'
opts.on('-a', '--action=NAME', ACTION_LIST, "The action for the sidecar to take. Expected #{ACTION_LIST}") do |name|
args[:action] = name
end
opts.on('-c', '--action-parameters=JSON', 'JSON Encoded string containing the parameters for the sidecar action') do |json_string|
ap = PuppetLanguageServer::Sidecar::Protocol::ActionParams.new
begin
ap.from_json!(json_string)
args[:action_parameters] = ap
rescue StandardError => e
raise "Unable to parse the action parameters: #{e}"
end
end
opts.on('-w', '--local-workspace=PATH', 'The workspace or file path that will be used to provide module-specific functionality. Default is no workspace path') do |path|
args[:workspace] = path
end
opts.on('-o', '--output=PATH', 'The file to save the output from the sidecar. Default is output to STDOUT') do |path|
args[:output] = path
end
opts.on('-p', '--puppet-settings=TEXT', Array, 'Comma delimited list of settings to pass into Puppet e.g. --vardir,/opt/test-fixture') do |text|
args[:puppet_settings] = text
end
opts.on('--puppet-version=TEXT', String, 'The version of the Puppet Gem to use (defaults to latest version if not specified or the version does not exist) e.g. --puppet-version=5.4.0') do |text|
args[:puppet_version] = text
end
opts.on('-f', '--feature-flags=FLAGS', Array, 'A list of comma delimited feature flags to pass the the sidecar') do |flags|
args[:flags] = flags
end
opts.on('-n', '--[no-]cache', 'Enable or disable all caching inside the sidecar. By default caching is enabled.') do |cache|
args[:disable_cache] = !cache
end
opts.on('--debug=DEBUG', "Output debug information. Either specify a filename or 'STDOUT'. Default is no debug output") do |debug|
args[:debug] = debug
end
opts.on('-h', '--help', 'Prints this help') do
puts opts
exit
end
opts.on('-v', '--version', 'Prints the Langauge Server version') do
puts PuppetLanguageServerSidecar.version
exit
end
end
opt_parser.parse!(options.dup)
raise('The action parameter is mandatory') if args[:action].nil?
args
end
|