Sha256: bf339761a7fe8c32f56dd9333b6f209e9fa96b474cb9dda693b8353c0439eba0

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
require 'cgi'


options = OpenStruct.new

OptionParser.new do |opts|
  opts.banner = "USAGE: mandy-local my_script.rb local_input_file local_output_folder [options]"
  
  opts.on("-v", '--variables name=value', "Pass additional parameters to jobs") do |config|
    options.cmdenv = config
  end
  
  opts.on("-j", '--json {"key":"1 value"}', "Pass JSON encoded parameters to jobs") do |config|
    options.cmdenv = "json=#{CGI.escape(config)}"
  end
  
  opts.on_tail("-h", "--help", "Show this message") do
    puts opts
    exit
  end
end.parse!

require "fileutils"

def absolute_path(path)
  path =~ /^\// ? path : File.join(Dir.pwd, path)
end

def set_env(opts_string)
  opts_string.split(' ').each do |pair|
    key, value = pair.split("=")
    ENV[key] = value
  end
end

set_env(options.cmdenv) if options.cmdenv 
file   = absolute_path(ARGV[0])
input  = absolute_path(ARGV[1])
output_folder = FileUtils.mkdir_p(absolute_path(ARGV[2]))
require file

out = nil
Mandy::Job.jobs.each_with_index do |job, i|
  out = File.join(output_folder, "#{i+1}-#{job.name.downcase.gsub(/\W/, '-')}")
  puts "Running #{job.name}..."
  `cat #{input} | mandy-map #{file} "#{job.name}" | sort | mandy-reduce #{file} "#{job.name}" > #{out}`
  input = out
end

puts out

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mandy-0.4 bin/mandy-local
mandy-0.3.13 bin/mandy-local
mandy-0.3.12 bin/mandy-local
mandy-0.3.11 bin/mandy-local