Sha256: c4f52458090c4080f1674669ee310669221d1f194992a521064ff439135f9092

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

require "guard/cli"

module Guard
  class ArubaAdapter
    def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR,
                   kernel = Kernel)
      @argv = argv
      @stdin = stdin
      @stdout = stdout
      @stderr = stderr
      @kernel = kernel

      if ENV["INSIDE_ARUBA_TEST"] == "1"
        ::Guard::UI.options = ::Guard::UI.options.merge(flush_seconds: 0)
      end
    end

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

    def execute
      # 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.
      ::Guard::CLI.start(@argv)

      # 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
      # flush the logger so the output doesn't appear in next CLI invocation
      ::Guard.listener.stop if ::Guard.listener
      ::Guard::UI.logger.flush
      ::Guard::UI.logger.close
      ::Guard::UI.reset_logger

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
guard-2.10.5 lib/guard/aruba_adapter.rb
guard-2.10.4 lib/guard/aruba_adapter.rb
guard-2.10.3 lib/guard/aruba_adapter.rb
guard-2.10.2 lib/guard/aruba_adapter.rb
guard-2.10.1 lib/guard/aruba_adapter.rb
guard-2.10.0 lib/guard/aruba_adapter.rb
guard-2.9.2 lib/guard/aruba_adapter.rb
guard-2.9.1 lib/guard/aruba_adapter.rb
guard-2.9.0 lib/guard/aruba_adapter.rb