Sha256: 0ba839fe212e94324bb75c3577e60c91c7025baece09b8f0abd367b98cbffac5

Contents?: true

Size: 625 Bytes

Versions: 3

Compression:

Stored size: 625 Bytes

Contents

# frozen_string_literal: true

module RunCommand
  class TTYStringIO < StringIO
    def tty?
      true
    end
  end

  def run_command(args, input: nil)
    stdout = StringIO.new
    stderr = StringIO.new
    stdin = input ? StringIO.new(input) : TTYStringIO.new
    exit_status = 0

    mod = if self.class.name.start_with?("CPF")
            CPF
          else
            CNPJ
          end

    begin
      CpfCnpj::CLI.new(mod, args, stdin, stdout, stderr).start
    rescue SystemExit => error
      exit_status = error.status
    end

    [exit_status, stdout.tap(&:rewind).read, stderr.tap(&:rewind).read]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cpf_cnpj-1.0.1 test/support/run_command.rb
cpf_cnpj-1.0.0 test/support/run_command.rb
cpf_cnpj-0.6.0 test/support/run_command.rb