Module: ImageFilterDsl::Engine::CLI
Overview
CLI Argument parser and handler module
Defined Under Namespace
Classes: Options
Constant Summary collapse
- RequiredArgs =
{ process: [:filter, :input, :output], compile: [:input, :output] }
Instance Method Summary collapse
Instance Method Details
#do_action(opts) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/image_filter_dsl/engine/cli.rb', line 73 def do_action(opts) if opts.action == :process ip = ImageFilterDsl.image_processor(opts.filter) ip.process_image(opts.input, opts.output) elsif opts.action == :compile print "(Not yet implemented :)\n" end end |
#parse(args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/image_filter_dsl/engine/cli.rb', line 18 def parse(args) opts = Options.new args=args.map{|s|s.strip} p = args[0] if !p.nil? && p.downcase == '--process' opts.action = :process elsif !p.nil? && p.downcase == '--compile' opts.action = :compile end unless opts.action.nil? case opts.action when :process f,i,o = args[1..-1] opts.filter = f opts.input = i opts.output = o when :compile s,k = args[1..-1] opts.input = s opts.output = k end end return opts end |
#run ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/image_filter_dsl/engine/cli.rb', line 47 def run() = parse(ARGV) if .action.nil? show_usage else p if RequiredArgs[.action].select{|o| [o].nil?}.length == 0 do_action() else show_usage(.action) end end end |
#show_usage(action = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/image_filter_dsl/engine/cli.rb', line 61 def show_usage(action=nil) if !action.nil? print "Invalid arguments for #{action.to_s}\n" end print [ "Usage: image_filter_dsl <action<", "\t--process <kernel_file> <image in> <image out>\t\tProcess image with binary kernel", "\t--compile <source_file> <output_kernel>\t\tCompile given ruby source to binary kernel" ].join("\n") print "\n" end |