Skip to content

Commit

Permalink
fix: expose better printing
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmerrell committed Feb 9, 2024
1 parent 0de3690 commit 4767fe2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/project/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ func (sshConn *SSHConnection) RunCommands(commands []string) error {
if err != nil {
return fmt.Errorf("failed to get stdout pipe: %w", err)
}
go scanAndPrint(stdout, stdoutColor, sshConn.podId)
go scanAndPrint(stdout, stdoutColor, sshConn.podId, showPrefixInPodLogs)

stderr, err := session.StderrPipe()
if err != nil {
return fmt.Errorf("failed to get stderr pipe: %w", err)
}
go scanAndPrint(stderr, stderrColor, sshConn.podId)
go scanAndPrint(stderr, stderrColor, sshConn.podId, showPrefixInPodLogs)

// Run the command
fullCommand := strings.Join([]string{
Expand All @@ -195,10 +195,13 @@ func (sshConn *SSHConnection) RunCommands(commands []string) error {
}

// Utility function to scan and print output from SSH sessions.
func scanAndPrint(pipe io.Reader, color *color.Color, podID string) {
func scanAndPrint(pipe io.Reader, color *color.Color, podID string, showPodIdPrefix bool) {
scanner := bufio.NewScanner(pipe)
for scanner.Scan() {
color.Printf("[%s] %s\n", podID, scanner.Text())
if showPodIdPrefix {
color.Printf("[%s] ", podID)
}
fmt.Println(scanner.Text())
}
}

Expand Down

0 comments on commit 4767fe2

Please sign in to comment.