Class: Vanagon::OptParse

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

Instance Method Summary collapse

Constructor Details

#initialize(banner, symbols = []) ⇒ OptParse

rubocop:disable Metrics/AbcSize



5
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vanagon/optparse.rb', line 5

def initialize(banner, symbols = []) # rubocop:disable Metrics/AbcSize
  ## symbols array kept for backward compatibility but ignored

  @options = Hash.new
  @options[:preserve] = :'on-failure'

  @option_parser = OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength
    opts.banner = banner
    opts.separator ""
    opts.separator "Options:"

    opts.on("-h",
            "--help",
            "Display help") do
      $stdout.puts opts
      exit 1
    end

    opts.on("-v",
            "--verbose",
            "Verbose output (does nothing)") do |verbose|
      @options[:verbose] = verbose
    end

    opts.on("-w DIRECTORY",
            "--workdir DIRECTORY",
            "Working directory on the local host (defaults to calling mktemp)") do |workdir|
      @options[:workdir] = workdir
    end

    opts.on("-r DIRECTORY",
            "--remote-workdir DIRECTORY",
            "Working directory on the remote host (defaults to calling mktemp)") do |remote|
      @options[:"remote-workdir"] = remote
    end

    opts.on("-c DIRECTORY",
            "--configdir DIRECTORY",
            "Configuration directory (defaults to $CWD/configs)") do |configuration_directory|
      @options[:configdir] = configuration_directory
    end

    opts.on("-e ENGINE",
            "--engine ENGINE",
            "Custom engine to use [base, local, docker, pooler] (defaults to \"pooler\")") do |engine|
      @options[:engine] = engine
    end

    opts.on("--skipcheck",
            "Skip the \"check\" stage when building components") do |skipcheck|
      @options[:skipcheck] = skipcheck
    end

    opts.on("-p [RULE]",
            "--preserve [RULE]",
            ["never", "on-failure", "always"],
            "Rule for VM preservation. [never, on-failure, always]") do |rule|
      if rule.nil?
        @options[:preserve] = :always
      else
        @options[:preserve] = rule.to_sym
      end
    end

    opts.on("--only-build COMPONENT,COMPONENT,...",
            Array,
            "Only build listed COMPONENTs") do |components|
      @options[:only_build] = components
    end
  end
end

Instance Method Details

#parse!(args) ⇒ Object



77
78
79
80
# File 'lib/vanagon/optparse.rb', line 77

def parse!(args)
  @option_parser.parse!(args)
  @options
end

#to_sObject



82
83
84
# File 'lib/vanagon/optparse.rb', line 82

def to_s
  @optparse.to_s
end