Class: Pechkin::CLI::CLIBuilder

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

Overview

Command Line Parser Builder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options_keeper) ⇒ CLIBuilder

Returns a new instance of CLIBuilder.



17
18
19
# File 'lib/pechkin/cli.rb', line 17

def initialize(options_keeper)
  @options = options_keeper
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/pechkin/cli.rb', line 16

def options
  @options
end

Instance Method Details

#build(parser) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



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
# File 'lib/pechkin/cli.rb', line 21

def build(parser) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  # rubocop:disable Metrics/LineLength
  parser.banner = 'Usage: pechkin [options]'
  parser.separator ''

  parser.on('-c', '--config CONFIG_FILE', 'default value is /etc/pechkin/config.yml') do |value|
    options.config_file = value
  end

  parser.on('-p', '--port PORT', Integer) do |value|
    options.port = value
  end

  parser.on('--pid PID_FILE') do |value|
    options.pid_file = value
  end

  parser.on('--log-dir LOG_DIR') do |value|
    options.log_dir = value
  end

  parser.separator ''
  parser.separator 'Common options:'
  parser.on_tail('-h', '--help', 'Show this message') do
    puts parser
    exit
  end

  # Another typical switch to print the version.
  parser.on_tail('--version', 'Show version') do
    puts Version.version_string
    exit
  end
  # rubocop:enable Metrics/LineLength
end