lib/filegen/runner.rb in filegen-0.0.1 vs lib/filegen/runner.rb in filegen-0.1.1

- old
+ new

@@ -1,22 +1,42 @@ # encoding: utf-8 module Filegen + # Commandline from end class Runner + private + attr_reader :options, :generator - def initialize(argv) - @options = Options.new(argv) - @generator = ErbGenerator.new(Env.new.my_binding) + public + + # Create runner + # @param [Array] argv + # Commandline arguments + # @param [IO] stdin + # Stdin + # @param [IO] stdout + # Stdout + # @param [IO] stderr + # Stderr + # @param [Kernel] kernel + # Kernel class + def initialize(argv, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = Kernel) + $stdin, $stdout, $stderr, @kernel = stdin, stdout, stderr, kernel + + @options = Options.new(argv) + @generator = ErbGenerator.new(Data.new(@options.data_sources)) end - def run + # Execute runner + def execute! begin - generator.compile(options.source,options.destination) - rescue Exception => e - puts e.message - exit 1 + generator.compile(options.source, options.destination) + exitstatus = 0 + rescue RuntimeError => e + $stderr.puts e.message + exitstatus = 1 end - exit 0 + @kernel.exit(exitstatus) end end end