Class: PuppetLanguageServer::CommandLineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_languageserver.rb

Class Method Summary collapse

Class Method Details

.parse(options) ⇒ Object



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
# File 'lib/puppet_languageserver.rb', line 111

def self.parse(options)
  # Set defaults here
  args = {
    connection_timeout: 10,
    debug: nil,
    disable_sidecar_cache: false,
    fast_start_langserver: true,
    flags: [],
    ipaddress: 'localhost',
    port: nil,
    puppet_version: nil,
    puppet_settings: [],
    preload_puppet: true,
    stdio: false,
    stop_on_client_exit: true,
    workspace: nil
  }

  opt_parser = OptionParser.new do |opts|
    opts.banner = 'Usage: puppet-languageserver.rb [options]'

    opts.on('-pPORT', '--port=PORT', 'TCP Port to listen on.  Default is random port') do |port|
      args[:port] = port.to_i
    end

    opts.on('-ipADDRESS', '--ip=ADDRESS', "IP Address to listen on (0.0.0.0 for all interfaces).  Default is #{args[:ipaddress]}") do |ipaddress|
      args[:ipaddress] = ipaddress
    end

    opts.on('-c', '--no-stop', 'Do not stop the language server once a client disconnects.  Default is to stop') do |_misc|
      args[:stop_on_client_exit] = false
    end

    opts.on('-tTIMEOUT', '--timeout=TIMEOUT', "Stop the language server if a client does not connection within TIMEOUT seconds.  A value of zero will not timeout.  Default is #{args[:connection_timeout]} seconds") do |timeout|
      args[:connection_timeout] = timeout.to_i
    end

    opts.on('-d', '--no-preload', '** DEPRECATED ** Do not preload Puppet information when the language server starts.  Default is to preload') do |_misc|
      puts '** WARNING ** Using "--no-preload" may cause Puppet Type loading to be incomplete.'
      args[:preload_puppet] = false
    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('-s', '--slow-start', '** DEPRECATED ** Delay starting the Language Server until Puppet initialisation has completed.  Default is to start fast') do |_misc|
      args[:fast_start_langserver] = false
    end

    opts.on('--stdio', 'Runs the server in stdio mode, without a TCP listener') do |_misc|
      args[:stdio] = true
    end

    opts.on('--enable-file-cache', '** DEPRECATED ** Enables the file system cache for Puppet Objects (types, class etc.)') do |_misc|
    end

    # These options are normally passed through to the Sidecar
    opts.on('--[no-]cache', 'Enable or disable all caching inside the sidecar. By default caching is enabled.') do |cache|
      args[:disable_sidecar_cache] = !cache
    end

    opts.on('--feature-flags=FLAGS', Array, 'A list of comma delimited feature flags') do |flags|
      args[:flags] = flags
    end

    opts.on('--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('--local-workspace=PATH', '** DEPRECATED ** The workspace or file path that will be used to provide module-specific functionality. Default is no workspace path.') do |_path|
    end

    opts.on('-h', '--help', 'Prints this help') do
      puts opts
      exit
    end

    opts.on('-v', '--version', 'Prints the Langauge Server version') do
      puts PuppetLanguageServer.version
      exit
    end
  end

  opt_parser.parse!(options.dup)
  args
end