Module: Cli

Defined in:
lib/cli.rb

Overview

Cli is a helper module for dealing with command line flags

Class Method Summary collapse

Class Method Details

.check_opts(options) ⇒ Object

Check options for any errors

Parameters:

  • options (Hash)

    The options to check



10
11
12
13
14
15
16
# File 'lib/cli.rb', line 10

def self.check_opts(options)
  %i[jobs env2conf].each do |key|
    if options[key].nil? || options[key].empty?
      raise ArgMissingError, key.to_s
    end
  end
end

.make_option_parser(options) ⇒ Object

Make an option parser bound to the hash passed in.

Parameters:

  • options (Hash)

    The hash that the options will be bound to on parse!

Returns:

  • (Object)

    The option parser that can be used.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cli.rb', line 22

def self.make_option_parser(options)
  OptionParser.new do |opts|
    opts.banner = 'Usage: configgin [options]'

    # Job definition file
    opts.on('-j', '--jobs file', 'Job definitions') do |j|
      options[:jobs] = j
    end

    # Environment to configuration templates file
    opts.on('-e', '--env2conf file',
            'Environment to configuration templates YAML') do |e|
      options[:env2conf] = e
    end

    opts.on('--version', 'Print the configgin version') do
      puts Configgin::VERSION
      exit 0
    end
  end
end