Sha256: e98c69abe4690b10361873bb7f3ba6b569572adfe9e5dfd02b22091654c39beb

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'certflare'
require 'certflare/logger'
module Certflare
  module Runner
    def initialize(argv = ARGV, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
      @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
    end

  end
  class CertflareRunner
    include Certflare::Runner

    def execute!
      exit_code = begin
        $stderr = @stderr
        $stdin  = @stdin
        $stdout = @stdout
        Certflare.init
        Certflare::CLI.start(@argv)
        0
      rescue StandardError => e
        b = e.backtrace
        STDERR.puts("#{b.shift}: #{e.message} (#{e.class})")
        STDERR.puts(b.map { |s| "\tfrom #{s}" }.join("\n"))
        1
      rescue SystemExit => e
        STDERR.puts e.status
        1
      ensure
        $stderr = STDERR
        $stdin  = STDIN
        $stdout = STDOUT
      end
      @kernel.exit(exit_code)
    end
  end
  class CertflareHookRunner
    include Runner
    def execute!
      exit_code = begin
        $stderr = @stderr
        $stdin  = @stdin
        $stdout = @stdout
        Certflare.init
        Certflare::HookCLI.start(@argv)
        0
      rescue StandardError => e
        b = e.backtrace
        STDERR.puts("#{b.shift}: #{e.message} (#{e.class})")
        STDERR.puts(b.map { |s| "\tfrom #{s}" }.join("\n"))
        1
      rescue SystemExit => e
        STDERR.puts e.status
        1
      ensure
        $stderr = STDERR
        $stdin  = STDIN
        $stdout = STDOUT
      end
      @kernel.exit(exit_code)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
certflare-0.1.10 lib/certflare/runner.rb