Small cosmetic fixes
This commit is contained in:
@@ -255,16 +255,14 @@ func parseTopicMessageCommand(c *cli.Context) (topic string, message string, com
|
|||||||
if c.String("message") != "" {
|
if c.String("message") != "" {
|
||||||
message = c.String("message")
|
message = c.String("message")
|
||||||
}
|
}
|
||||||
|
if message == "" && isStdinRedirected() {
|
||||||
// If no message provided and stdin has data, read from stdin
|
var bytes []byte
|
||||||
if message == "" && stdinHasData() {
|
bytes, err = io.ReadAll(c.App.Reader)
|
||||||
var stdinBytes []byte
|
|
||||||
stdinBytes, err = io.ReadAll(c.App.Reader)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to read from stdin: %v", err)
|
log.Debug("Failed to read from stdin: %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
message = strings.TrimSpace(string(stdinBytes))
|
message = strings.TrimSpace(string(bytes))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -325,10 +323,10 @@ func runAndWaitForCommand(command []string) (message string, err error) {
|
|||||||
return fmt.Sprintf("Command succeeded after %s: %s", runtime, prettyCmd), nil
|
return fmt.Sprintf("Command succeeded after %s: %s", runtime, prettyCmd), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func stdinHasData() bool {
|
func isStdinRedirected() bool {
|
||||||
stat, err := os.Stdin.Stat()
|
stat, err := os.Stdin.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to stat stdin: %v", err)
|
log.Debug("Failed to stat stdin: %s", err.Error())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return (stat.Mode() & os.ModeCharDevice) == 0
|
return (stat.Mode() & os.ModeCharDevice) == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user