Sha256: c42796ea7224445b87a0f92c866c776157879484f3b9fe0b26a80ee373a342e1

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8
module Filegen
  # Commandline from end
  class Runner
    private

    attr_reader :argv

    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)
      @argv, $stdin, $stdout, Ui.logger, @kernel = argv, stdin, stdout, stderr, kernel
    end

    # Execute runner
    def execute!
      begin
        options   = Options.new(argv)

        generator = ErbGenerator.new(Data.new(options.data_sources))
        generator.compile(options.source, options.destination)

        exitstatus = 0
      rescue RuntimeError => e
        Filegen::Ui.error e.message
        exitstatus = 1
      rescue Interrupt => e
        Filegen::Ui.warning 'You told me to stop command execution.'
        exitstatus = 2
      end

      @kernel.exit(exitstatus)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
filegen-0.3.0 lib/filegen/runner.rb
filegen-0.2.3 lib/filegen/runner.rb