From 9ed96e5d8b16944d40a6e2e6a2ddf924112a2fc5 Mon Sep 17 00:00:00 2001 From: srevn Date: Sun, 6 Jul 2025 16:31:03 +0300 Subject: [PATCH] Small cosmetic fixes --- cmd/publish.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cmd/publish.go b/cmd/publish.go index 1d04b537..d1ccf79a 100644 --- a/cmd/publish.go +++ b/cmd/publish.go @@ -255,16 +255,14 @@ func parseTopicMessageCommand(c *cli.Context) (topic string, message string, com if c.String("message") != "" { message = c.String("message") } - - // If no message provided and stdin has data, read from stdin - if message == "" && stdinHasData() { - var stdinBytes []byte - stdinBytes, err = io.ReadAll(c.App.Reader) + if message == "" && isStdinRedirected() { + var bytes []byte + bytes, err = io.ReadAll(c.App.Reader) if err != nil { - log.Debug("Failed to read from stdin: %v", err) + log.Debug("Failed to read from stdin: %s", err.Error()) return } - message = strings.TrimSpace(string(stdinBytes)) + message = strings.TrimSpace(string(bytes)) } return } @@ -325,10 +323,10 @@ func runAndWaitForCommand(command []string) (message string, err error) { return fmt.Sprintf("Command succeeded after %s: %s", runtime, prettyCmd), nil } -func stdinHasData() bool { +func isStdinRedirected() bool { stat, err := os.Stdin.Stat() if err != nil { - log.Debug("Failed to stat stdin: %v", err) + log.Debug("Failed to stat stdin: %s", err.Error()) return false } return (stat.Mode() & os.ModeCharDevice) == 0