Sha256: 72765fdd83a4788d5b3b3792aea7935a7e2f204d8270aeb7d50cf363c2de647c

Contents?: true

Size: 1.73 KB

Versions: 10

Compression:

Stored size: 1.73 KB

Contents

require 'aruba'
require 'aruba/in_process'
require 'aruba/cucumber'

require 'csvlint/cli'

module Csvlint
  class CliRunner
    # Allow everything fun to be injected from the outside while defaulting to normal implementations.
    def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
      @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
    end

    def execute!
      exit_code = begin
        # Thor accesses these streams directly rather than letting them be injected, so we replace them...
        $stderr = @stderr
        $stdin = @stdin
        $stdout = @stdout

        # Run our normal Thor app the way we know and love.
        Csvlint::Cli.start(@argv.dup.unshift("validate"))

        # Thor::Base#start does not have a return value, assume success if no exception is raised.
        0
      rescue StandardError => e
        # The ruby interpreter would pipe this to STDERR and exit 1 in the case of an unhandled exception
        b = e.backtrace
        @stderr.puts("#{b.shift}: #{e.message} (#{e.class})")
        @stderr.puts(b.map{|s| "\tfrom #{s}"}.join("\n"))
        1
      rescue SystemExit => e
        e.status
      ensure
        # TODO: reset your app here, free up resources, etc.
        # Examples:
        # MyApp.logger.flush
        # MyApp.logger.close
        # MyApp.logger = nil
        #
        # MyApp.reset_singleton_instance_variables

        # ...then we put the streams back.
        $stderr = STDERR
        $stdin = STDIN
        $stdout = STDOUT
      end

      # Proxy our exit code back to the injected kernel.
      @kernel.exit(exit_code)
    end
  end
end

Aruba.process = Aruba::Processes::InProcess
Aruba.process.main_class = Csvlint::CliRunner

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
csvlint-0.4.0 features/support/aruba.rb
csvlint-0.3.3 features/support/aruba.rb
csvlint-0.3.2 features/support/aruba.rb
csvlint-0.3.1 features/support/aruba.rb
csvlint-0.3.0 features/support/aruba.rb
wjordan213-csvlint-0.2.8 features/support/aruba.rb
wjordan213.csvlint-0.2.8 features/support/aruba.rb
csvlint-0.2.6 features/support/aruba.rb
csvlint-0.2.5 features/support/aruba.rb
csvlint-0.2.4 features/support/aruba.rb