Sha256: aad54ca6ca64635adee66cfd0562b3c0d249efc2372f701fe086da8687e1bfdb

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'arli'
require 'arli/cli/app'

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
          print_debug_info
          0
        rescue StandardError => e
          b = e.backtrace
          @stderr.puts("#{b.shift.bold}:\n") if Arli.config.debug
          @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
        end
        @kernel.exit(exit_code)
      end

      def print_debug_info
        $stdout.puts JSON.pretty_generate(Arli.config.to_hash).gsub(/("\w+":)/, '\1'.bold.blue) \
          if Arli.config.debug
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arli-1.0.0 lib/arli/cli/runner.rb