Sha256: 28c4cbf02b2812ba199d5ed99d6823ddb0b3d0cc546033e4d1ddca92aedb1e6a

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require 'colored2'
require 'arli/cli/app'
require 'pp'
module Arli
  module CLI
    # For the reasons this file is the way it is, please refer to
    # https://github.com/erikhuda/thor/wiki/Integrating-with-Aruba-In-Process-Runs
    class Runner
      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
          $stderr = @stderr
          $stdin  = @stdin
          $stdout = @stdout

          Arli::CLI::App.new(@argv).start
          0
        rescue StandardError => e
          b = e.backtrace
          @stderr.puts("#{b.shift.bold}:\n")
          @stderr.puts("#{e.message.bold.red} (#{e.class.name.yellow})")
          @stderr.puts(b.map { |s| "\tfrom #{s}" }.join("\n")).red
          1
        rescue SystemExit => e
          e.status
        ensure
          $stderr = STDERR
          $stdin  = STDIN
          $stdout = STDOUT
          ap(Arli.config.to_hash, indent: 6, index: false) if Arli.config.debug
        end
        @kernel.exit(exit_code)
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
arli-0.7.0 lib/arli/cli/runner.rb
arli-0.6.2 lib/arli/cli/runner.rb
arli-0.6.1 lib/arli/cli/runner.rb