51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/athena/cli.rb', line 51
def run(arguments)
spec = options[:spec] || options[:spec_fallback]
abort "No input format (spec) specified and none could be inferred." unless spec
abort "Invalid input format (spec): #{spec}. Use `-L' to get a list of available specs." unless Athena.valid_input_format?(spec)
format = options[:format] || options[:format_fallback]
abort "No output format specified and none could be inferred." unless format
abort "Invalid output format: #{format}. Use `-l' to get a list of available formats." unless Athena.valid_output_format?(format)
if t = options[:target]
target_config = config[target = t.to_sym]
else
[options[:target_fallback] || 'generic', ".#{spec}", ":#{format}"].inject([]) { |s, t|
s << (s.last ? s.last + t : t)
}.reverse.find { |t| target_config = config[target = t.to_sym] }
end or abort "Config not found for target: #{target}."
input = options[:input]
input = arguments.shift unless input != defaults[:input] || arguments.empty?
input = File.directory?(input) ? Dir.open(input) : open_file_or_std(input)
quit unless arguments.empty?
Athena.run(target_config, spec, format, input, open_file_or_std(options[:output], true))
end
|