Sha256: 2c1ff3efc9ce880b997a3d0490b8cc401eee9bd55349745fb085a25779acfda2

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'optparse'
require 'generate'
require 'exceptions'

# 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)
    [: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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
configgin-0.12.0 lib/cli.rb
configgin-0.12.0.pre lib/cli.rb