Sha256: e28d663f7744bca0fcb843caae42501aa4552b51df379e33189ba4da1330b5fa

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

require 'thor'
require 'chronicle/etl'

module Chronicle
  module Etl
    class CLI < Thor
      default_task :job

      desc 'job', 'Runs an ETL job'
      method_option :extractor, aliases: '-e', desc: 'Extractor class (available: stdin, csv, file)', default: 'stdin', banner: 'extractor-name'
      method_option :'extractor-opts', desc: 'Extractor options', type: :hash, default: {}
      method_option :transformer, aliases: '-t', desc: 'Transformer class (available: null)', default: 'null', banner: 'transformer-name'
      method_option :'transformer-opts', desc: 'Transformer options', type: :hash, default: {}
      method_option :loader, aliases: '-l', desc: 'Loader class (available: stdout, csv, table)', default: 'stdout', banner: 'loader-name'
      method_option :'loader-opts', desc: 'Loader options', type: :hash, default: {}
      method_option :job, aliases: '-j', desc: 'Job configuration file'

      def job
        runner_options = {
          extractor: {
            name: options[:extractor],
            options: options[:'extractor-opts']
          },
          transformer: {
            name: options[:transformer],
            options: options[:'transformer-opts']
          },
          loader: {
            name: options[:loader],
            options: options[:'loader-opts']
          }
        }

        runner = Runner.new(runner_options)
        runner.run!
      end

      # FIXME: namespace this differently
      desc 'list', 'List all ETL classes'
      def list
        klasses = Chronicle::Etl::Catalog.available_classes

        table = TTY::Table.new(['class_name', 'built_in?', 'provider', 'phase'], klasses.map(&:values))
        puts table.render
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chronicle-etl-0.1.3 lib/chronicle/etl/cli.rb