#!/usr/bin/env ruby require 'rbbt/util/simpleopt' require 'rbbt/workflow' require 'rbbt/workflow/usage' def load_inputs(dir, task) inputs = {} dir = Path.setup(dir.dup) task.inputs.each do |input| file = dir[input].find Log.debug "Trying #{ input }: #{file}" next unless file.exists? case task.input_types[input] when :tsv, :array, :text Log.debug "Pointing #{ input } to #{file}" inputs[input.to_sym] = file else Log.debug "Loading #{ input } from #{file}" inputs[input.to_sym] = file.read.strip end end IndiferentHash.setup(inputs) end def report_options(options) if options.nil? or options.empty? puts "No options" else options.each do |key, value| puts [Log.color(:cyan, key), Misc.fingerprint(value)] * ": " end end end def usage(workflow = nil, task = nil, exception=nil) puts SOPT.doc puts if workflow.nil? puts "No workflow specified" exit -1 end if task.nil? workflow.load_tasks if workflow.respond_to? :load_tasks workflow.doc puts puts "E.g. rbbt workflow task #{workflow.to_s} #{workflow.tasks.keys.first.to_s} -h" else puts Log.color :magenta, workflow.to_s puts Log.color :magenta, "=" * workflow.to_s.length puts puts workflow.documentation[:description] puts workflow.doc(task) end print_error(exception.message, exception.backtrace) if exception true end def SOPT_options(workflow, task) sopt_options = [] workflow.rec_inputs(task.name).each do |name| short = name.to_s.chars.first boolean = workflow.rec_input_types(task.name)[name].to_sym == :boolean sopt_options << "-#{short}--#{name}#{boolean ? "" : "*"}" end sopt_options * ":" end def fix_options(workflow, task, job_options) option_types = workflow.rec_input_types(task.name) job_options_cleaned = {} job_options.each do |name, value| value = case option_types[name].to_sym when :boolean TrueClass === true or %w(true TRUE T yes).include? value when :float value.to_f when :integer value.to_i when :text case when value == '-' STDIN.read when (String === value and File.exists?(value) and not File.directory?(value)) Open.read(value) else value end when :array if Array === value value else str = case when value == '-' STDIN.read when (String === value and File.exists?(value)) Open.read(value) else value end if $array_separator str.split(/#{$array_separator}/) else str.split(/[,|\s]/) end end when :tsv case value when TSV value when '-' TSV.open(STDIN, :unnamed => true) else TSV.open(value, :unnamed => true) end else value end job_options_cleaned[name] = value end job_options_cleaned end options = SOPT.get <