-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Automatically split STDIN on null characters on push #70
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: eternal-flame-AD <[email protected]>
Signed-off-by: eternal-flame-AD <[email protected]>
Signed-off-by: eternal-flame-AD <[email protected]>
read := bufio.NewReader(r) | ||
for { | ||
s, err := read.ReadString('\x00') | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified, if we always trim the suffix:
s, err := read.ReadString('\x00')
s = strings.TrimSuffix(s, "\x00")
if len(s) > 0 {
output <- s
}
if errors.Is(err, io.EOF) {
return
}
if err != nil {
utils.Exit1With("read error", err)
}
@@ -31,6 +30,7 @@ func Push() cli.Command { | |||
cli.StringFlag{Name: "contentType", Usage: "The content type of the message. See https://gotify.net/docs/msgextras#client-display"}, | |||
cli.StringFlag{Name: "clickUrl", Usage: "An URL to open upon clicking the notification. See https://gotify.net/docs/msgextras#client-notification"}, | |||
cli.BoolFlag{Name: "disable-unescape-backslash", Usage: "Disable evaluating \\n and \\t (if set, \\n and \\t will be seen as a string)"}, | |||
cli.BoolFlag{Name: "no-split", Usage: "Do not split the message on null character when reading from stdin"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we invert this, so we don't changing existing behavior (reading stdin completely and pushing one message).
@@ -71,7 +71,7 @@ func inputConfigLocation() string { | |||
for { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would I use this feature to simplify the journalctl call in #69?
I'm also not 100% sure about the actual use-case of feature, is there something not possible with the current cli feature set and xargs? I don't find the argument that we don't have to use xargs very strong for implementing this inside gotify/cli.
I think if someone doesn't have access to xargs then they probably don't use gotify/cli and instead use some "raw" http call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would I use this feature to simplify the journalctl call in #69?
journalctl -f -u sshd | awk 'NR % 5 == 0 { print "\0"} { print }' | gotify push
is there something not possible with the current cli feature set and xargs
makes sense, maybe I will just cherry pick the formatting bugs to a different PR and do that
This fixes #69.
Added a feature to split on null characters when reading from stdin. This way users can have one long-running
gotify push
and simply piping things to it.