piotrmurach / tty-command

Execute shell commands with pretty output logging and capture stdout, stderr and exit status.
https://ttytoolkit.org
MIT License
400 stars 34 forks source link

Quiet printer puts using print instead of << #29

Closed jamesepatrick closed 7 years ago

jamesepatrick commented 7 years ago

Hey everyone,

I'm not sure if this is an issue but the Quiet Printer uses output.print(message) instead of output << message as referenced in the readme.md file.

Running

#! /usr/bin/env ruby

require 'tty-command'

# Class prints and logs output of cmd
class Tee
  def initialize(file)
    @file = file
  end
  def <<(message)
   @file << message
   puts message
  end
end

# Command System
tee = Tee.new( File.open('foo.log', 'w') )
cmd = TTY::Command.new( output: tee, printer: :quiet )

cmd.run 'ping google.com -c 3'

results in an error of :

/Users/james/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/tty-command-0.4.0/lib/tty/command/printers/quiet.rb:20:in `write': private method `print' called for #<Tee:0x007f82db191558 @file=#<File:foo.log>> (NoMethodError)
        from /Users/james/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/tty-command-0.4.0/lib/tty/command/printers/abstract.rb:33:in `print_command_out_data'
        from /Users/james/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/tty-command-0.4.0/lib/tty/command/process_runner.rb:66:in `block in read_streams'

Put using the pretty printer instead works without issue. Changing << -> write or aliasing works as well.

piotrmurach commented 7 years ago

I've added your example as an integration test.

jamesepatrick commented 7 years ago

Awesome, thank you @piotrmurach.