Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

eternal-flame-AD
Copy link
Member

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.

@eternal-flame-AD eternal-flame-AD requested a review from a team as a code owner August 4, 2024 21:49
command/read.go Outdated Show resolved Hide resolved
command/push.go Outdated Show resolved Hide resolved
command/watch.go Outdated Show resolved Hide resolved
command/push.go Show resolved Hide resolved
command/push.go Outdated Show resolved Hide resolved
command/read.go Outdated Show resolved Hide resolved
command/push.go Outdated Show resolved Hide resolved
read := bufio.NewReader(r)
for {
s, err := read.ReadString('\x00')
if err != nil {
Copy link
Member

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"},
Copy link
Member

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).

command/push.go Show resolved Hide resolved
@@ -71,7 +71,7 @@ func inputConfigLocation() string {
for {
Copy link
Member

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.

Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Feature: New option to push message every x lines(default 1)
2 participants