Sha256: f489afb542969a8816580715acf3c3f68714a67a5d11224f93e0b20334f08b8a

Contents?: true

Size: 1.18 KB

Versions: 12

Compression:

Stored size: 1.18 KB

Contents

require 'optparse'
require_relative 'exceptions'
require_relative 'configgin/version'

# Cli is a helper module for dealing with command line flags
module Cli
  # Check options for any errors
  #
  # @param options [Hash] The options to check
  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 an option parser bound to the hash passed in.
  #
  # @param options [Hash]   The hash that the options will be bound to on parse!
  # @return        [Object] The option parser that can be used.
  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
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
configgin-0.17.0 lib/cli.rb
configgin-0.16.3 lib/cli.rb
configgin-0.16.2 lib/cli.rb
configgin-0.15.2 lib/cli.rb
configgin-0.15.1 lib/cli.rb
configgin-0.16.1 lib/cli.rb
configgin-0.16.0 lib/cli.rb
configgin-0.15.0 lib/cli.rb
configgin-0.14.1 lib/cli.rb
configgin-0.14.0 lib/cli.rb
configgin-0.13.0 lib/cli.rb
configgin-0.12.1 lib/cli.rb