mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-07-20 10:04:08 +00:00
Small cosmetic fixes
This commit is contained in:
parent
04aff72631
commit
9ed96e5d8b
1 changed files with 7 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue