class ComposeEnv::InputParser

Parse input options. Prepare the options for being pipelined to the follow-up processors.

Constants

DEFAULT_ENVS
DEFAULT_FILE
Options

Public Class Methods

parse(options) click to toggle source
# File lib/compose_env/input_parser.rb, line 10
def self.parse(options)
  new.parse(options)
end

Public Instance Methods

parse(options) click to toggle source
# File lib/compose_env/input_parser.rb, line 14
def parse(options)
  prepared_options = prepare(options)
  option_parser.parse!(prepared_options)
  return args
end

Private Instance Methods

args() click to toggle source
# File lib/compose_env/input_parser.rb, line 41
def args
  @args ||= Options.new(DEFAULT_ENVS, normalize_file(DEFAULT_FILE))
end
normalize_envs(envs) click to toggle source
# File lib/compose_env/input_parser.rb, line 45
def normalize_envs(envs)
  envs.split(',').map(&:strip).map(&:to_sym)
end
normalize_file(file) click to toggle source
# File lib/compose_env/input_parser.rb, line 49
def normalize_file(file)
  Pathname.new(Dir.pwd).join(file).to_s
end
option_parser() click to toggle source
# File lib/compose_env/input_parser.rb, line 22
def option_parser
  OptionParser.new do |opts|
    opts.banner = "Usage: compose-env [options]"

    opts.on("-eENVIROMENTS", "--envs=ENVIRONMENTS", "List of environments") do |envs|
      args.envs = normalize_envs(envs)
    end

    opts.on("-fFILE", "--file=FILE", "The name of a template file to parse") do |file|
      args.file = normalize_file(file)
    end

    opts.on("-h", "--help", "Prints this help") do
      puts opts
      exit
    end
  end
end
prepare(options) click to toggle source

Prepare a comma separated string to be parsed as one argument even with whitespaces in it

# File lib/compose_env/input_parser.rb, line 54
def prepare(options)
  options.join(' ').gsub(/\s*,\s*/, ',').split(' ')
end