Sha256: 6aa447d1729749c3e9876249ceb4870ca5634aa54a7ecf8e84b88e5225033130

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

module Metacrunch
  class Cli
    ARGS_SEPERATOR = "@@"

    def run
      init_commander!
      init_run_command!
      run_commander!
    end

  private
    def commander
      @commander ||= Commander::Runner.new(metacrunch_args)
    end

    def init_commander!
      commander.program :name, "metacrunch"
      commander.program :version, Metacrunch::VERSION
      commander.program :description, "Data processing and ETL toolkit for Ruby."
      commander.default_command :help
    end

    def run_commander!
      commander.run!
    end

    def init_run_command!
      commander.command :run do |c|
        c.syntax = "metacrunch run [options] FILE [@@ job_options]"
        c.description = "Runs a metacrunch job description."

        c.action do |filenames, program_options|
          if filenames.empty?
            say "You need to provide a job description file."
            exit(1)
          elsif filenames.count > 1
            say "You must provide exactly one job description file."
          else
            filename = File.expand_path(filenames.first)
            dir = File.dirname(filename)

            Dir.chdir(dir) do
              Metacrunch::Job.define(File.read(filename), filename: filename, args: job_args).run
            end
          end
        end
      end
    end

    def metacrunch_args
      index = ARGV.index(ARGS_SEPERATOR)
      @metacrunch_args ||= index ? ARGV[0..index-1] : ARGV
    end

    def job_args
      index = ARGV.index(ARGS_SEPERATOR)
      @job_args ||= index ? ARGV[index+1..-1] : nil
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
metacrunch-3.0.3 lib/metacrunch/cli.rb
metacrunch-3.0.2 lib/metacrunch/cli.rb
metacrunch-3.0.1 lib/metacrunch/cli.rb