fix: bad line length character caused by printing to stdout

using stderr instead
This commit is contained in:
juancwu 2026-01-12 18:06:02 -05:00
commit e334a472b5
2 changed files with 19 additions and 9 deletions

View file

@ -23,9 +23,19 @@ func startEphemeralAgent(pemData []byte, target string) (string, func(), error)
if err != nil {
if _, ok := err.(*ssh.PassphraseMissingError); ok {
fmt.Printf("\033[1;32mGosh:\033[0m Key for \033[1m%s\033[0m is encrypted. Enter passphrase: ", target)
pass, readErr := term.ReadPassword(int(syscall.Stdin))
fmt.Println()
var promptWriter *os.File = os.Stderr
var inputFd int = int(syscall.Stdin)
tty, ttyErr := getTTY()
if ttyErr == nil {
defer tty.Close()
promptWriter = tty
inputFd = int(tty.Fd())
}
fmt.Fprintf(promptWriter, "\033[1;32mGosh:\033[0m Key for \033[1m%s\033[0m is encrypted. Enter passphrase: ", target)
pass, readErr := term.ReadPassword(inputFd)
fmt.Fprintln(promptWriter)
if readErr != nil {
return "", nil, fmt.Errorf("failed to read password: %w", err)
}
@ -38,7 +48,7 @@ func startEphemeralAgent(pemData []byte, target string) (string, func(), error)
return "", nil, fmt.Errorf("invalid key format: %w", err)
}
} else {
fmt.Printf("Using unencrypted key for %s\n", target)
fmt.Fprintf(os.Stderr, "Using unencrypted key for %s\n", target)
}
keyring := agent.NewKeyring()
@ -93,7 +103,7 @@ func startSSH(storePath string, args []string) {
socketPath, cleanup, err := startEphemeralAgent(pemData, targetName)
if err != nil {
fmt.Println("Error:", err)
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
defer cleanup()
@ -110,7 +120,7 @@ func startSSH(storePath string, args []string) {
sshPath, err := exec.LookPath("ssh")
if err != nil {
fmt.Println("Error:", err)
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
@ -132,7 +142,7 @@ func startSSH(storePath string, args []string) {
err = sshCmd.Run()
if err != nil {
fmt.Println("Error:", err)
fmt.Fprintln(os.Stderr, "Error:", err)
if exitErr, ok := err.(*exec.ExitError); ok {
os.Exit(exitErr.ExitCode())
}