Class: PuppetDebugServer::CommandLineParser

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

Class Method Summary collapse

Class Method Details

.parse(options) ⇒ Object



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

def self.parse(options)
  # Set defaults here
  args = {
    port: nil,
    ipaddress: 'localhost',
    stop_on_client_exit: true,
    connection_timeout: 10,
    debug: nil,
    puppet_version: nil
  }

  opt_parser = OptionParser.new do |opts|
    opts.banner = 'Usage: puppet-debugserver.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('-tTIMEOUT', '--timeout=TIMEOUT', "Stop the Debug 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('--debug=DEBUG', "Output debug information.  Either specify a filename or 'STDOUT'.  Default is no debug output") do |debug|
      args[:debug] = debug
    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('-h', '--help', 'Prints this help') do
      puts opts
      exit
    end

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

  opt_parser.parse!(options.dup)
  args
end