Class: SnowmanIO::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/snowman-io/options.rb

Overview

Parse command line.

Instance Method Summary collapse

Instance Method Details

#parse!(args) ⇒ Object



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
# File 'lib/snowman-io/options.rb', line 6

def parse!(args)
  options = default_options

  opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: snowman [options]"

    opts.separator ""
    opts.separator "Options:"
    opts.on("-p", "--port PORT", "use PORT (default: #{default_options[:port]})") do |port|
      options[:port] = port.to_i
    end

    opts.on "-v", "--verbose", "print more verbose output" do |arg|
      options[:verbose] = arg
    end

    opts.on '-t', '--timeout NUM', "shutdown timeout (default #{default_options[:timeout]} seconds)" do |arg|
      options[:timeout] = Integer(arg)
    end

    opts.on("-h", "--help", "show this message") do
      puts opts
      exit
    end
  end

  opt_parser.parse!(args)
  options
end