Sha256: 12a3049fcaaf25ec55bfa315fd9b1c2bc1287d4f9b08543e94f05deb59717025

Contents?: true

Size: 904 Bytes

Versions: 1

Compression:

Stored size: 904 Bytes

Contents

require "erb"
require "optparse"
require "transformator"
require "yaml"

require "pry"  # TODO: remove

class Transformator::Cli
  def initialize(argv = [])
    if argv.empty?
      puts options_parser.help
    else
      @options = parse_argv(argv) || {}
    end

    Transformator::Dispatcher.new(
      YAML.load(
        ERB.new(
          File.read(
            File.expand_path(@options[:config_file_name])
          )
        ).result
      )
    ).call
  end

  def parse_argv(argv)
    presence({}.tap do |result|
      OptionParser.new do |opts|
        opts.banner = "Usage: transformator [options]"

        opts.on( "-c", "--config-file FILE", "Configuration file in yaml format" ) do |config_file_name|
          result[:config_file_name] = config_file_name
        end
      end.parse(argv)
    end)
  end

  def presence(object)
    (object.empty? rescue false) ? nil : object 
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
transformator-1.0.0.pre1 lib/transformator/cli.rb