mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-07-20 10:04:08 +00:00
Add piping support
This commit is contained in:
parent
30301c8a7f
commit
6fbcd85d17
1 changed files with 18 additions and 0 deletions
|
@ -254,6 +254,16 @@ 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 no message provided and stdin has data, read from stdin
|
||||||
|
if message == "" && stdinHasData() {
|
||||||
|
var stdinBytes []byte
|
||||||
|
stdinBytes, err = io.ReadAll(c.App.Reader)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
message = strings.TrimSpace(string(stdinBytes))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,3 +322,11 @@ func runAndWaitForCommand(command []string) (message string, err error) {
|
||||||
log.Debug("Command succeeded after %s: %s", runtime, prettyCmd)
|
log.Debug("Command succeeded after %s: %s", runtime, prettyCmd)
|
||||||
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 {
|
||||||
|
stat, err := os.Stdin.Stat()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return (stat.Mode() & os.ModeCharDevice) == 0
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue