Skip to content

Commit

Permalink
Add hostname as prefix for SSH output lines
Browse files Browse the repository at this point in the history
  • Loading branch information
vitobotta committed Apr 12, 2024
1 parent ee88d21 commit e68cafa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/util/prefixed_io.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class PrefixedIO < IO
def initialize(@prefix : String, @io : IO); end

def read(slice : Bytes)
raise NotImplementedError.new "#read"
end

def write(slice : Bytes) : Nil
content = String.new(slice)
content.lines.each do |line|
@io << @prefix << "#{line}\n"
end
end
end
3 changes: 2 additions & 1 deletion src/util/ssh.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "io"
require "../util"
require "retriable"
require "tasker"
require "./prefixed_io"

class Util::SSH
getter private_ssh_key_path : String
Expand Down Expand Up @@ -42,7 +43,7 @@ class Util::SSH

result = IO::Memory.new
all_output = if print_output
IO::MultiWriter.new(STDOUT, result)
IO::MultiWriter.new(PrefixedIO.new("[#{server.name}] ", STDOUT), result)
else
IO::MultiWriter.new(result)
end
Expand Down

0 comments on commit e68cafa

Please sign in to comment.