diff --git a/blossom.go b/blossom.go index 94922f9..41e9ddf 100644 --- a/blossom.go +++ b/blossom.go @@ -305,7 +305,7 @@ if any of the files are not found the command will fail, otherwise it will succe return nil } - for input := range getJsonsOrBlank() { + for input := range getJsonsOrBlank(false) { if input == "{}" { continue } diff --git a/count.go b/count.go index 482a9e9..b2e84f2 100644 --- a/count.go +++ b/count.go @@ -43,7 +43,7 @@ var count = &cli.Command{ } // go line by line from stdin or run once with input from flags - for stdinFilter := range getJsonsOrBlank() { + for stdinFilter := range getJsonsOrBlank(false) { filter := nostr.Filter{} if stdinFilter != "" { if err := easyjson.Unmarshal([]byte(stdinFilter), &filter); err != nil { diff --git a/encode.go b/encode.go index ca543d6..c55e28f 100644 --- a/encode.go +++ b/encode.go @@ -48,7 +48,7 @@ func getEncodeSubcommandInput(args cli.Args, allowBlank bool) iter.Seq[string] { } return func(yield func(string) bool) { - for jsonStr := range getJsonsOrBlank() { + for jsonStr := range getJsonsOrBlank(false) { if jsonStr == "{}" { if allowBlank { yield("") @@ -96,7 +96,7 @@ var encode = &cli.Command{ } hasStdin := false - for jsonStr := range getJsonsOrBlank() { + for jsonStr := range getJsonsOrBlank(false) { if jsonStr == "{}" { hasStdin = false continue diff --git a/event.go b/event.go index c397df3..e3e9e5e 100644 --- a/event.go +++ b/event.go @@ -172,6 +172,11 @@ example: Usage: "ask before publishing the event", Category: CATEGORY_EXTRAS, }, + &cli.BoolFlag{ + Name: "github", + Usage: "treat empty stdin as no stdin at all, as GitHub Actions always opens it", + Category: CATEGORY_EXTRAS, + }, // hidden &cli.StringFlag{ @@ -442,7 +447,7 @@ example: return publishFlow(ctx, c, kr, evt, relays) } - for stdinEvent := range getJsonsOrBlank() { + for stdinEvent := range getJsonsOrBlank(c.Bool("github")) { if err := handleEvent(stdinEvent); err != nil { ctx = lineProcessingError(ctx, err.Error()) } diff --git a/filter.go b/filter.go index 9085dbf..eee6830 100644 --- a/filter.go +++ b/filter.go @@ -69,7 +69,7 @@ example: } // if there is no stdin we'll still get an empty object here - for evtj := range getJsonsOrBlank() { + for evtj := range getJsonsOrBlank(false) { var evt nostr.Event if err := easyjson.Unmarshal([]byte(evtj), &evt); err != nil { ctx = lineProcessingError(ctx, "invalid event: %s", err) diff --git a/gift.go b/gift.go index 15cca6d..714e659 100644 --- a/gift.go +++ b/gift.go @@ -92,7 +92,7 @@ a decoupled key (if it has been created or received with "nak dekey" previously) } // read event from stdin - for eventJSON := range getJsonsOrBlank() { + for eventJSON := range getJsonsOrBlank(false) { if eventJSON == "{}" { continue } @@ -185,7 +185,7 @@ a decoupled key (if it has been created or received with "nak dekey" previously) } // read gift-wrapped event from stdin - for wrapJSON := range getJsonsOrBlank() { + for wrapJSON := range getJsonsOrBlank(false) { if wrapJSON == "{}" { continue } diff --git a/helpers.go b/helpers.go index 19ef562..fb2fbbd 100644 --- a/helpers.go +++ b/helpers.go @@ -70,7 +70,7 @@ func isPiped() bool { return is } -func getJsonsOrBlank() iter.Seq[string] { +func getJsonsOrBlank(github bool) iter.Seq[string] { var curr strings.Builder var finalJsonErr error @@ -102,7 +102,7 @@ func getJsonsOrBlank() iter.Seq[string] { return } - if !hasStdin { + if !hasStdin && (!isPiped() || github) { if !yield("{}") { return } diff --git a/req.go b/req.go index c52a029..4acfac5 100644 --- a/req.go +++ b/req.go @@ -155,7 +155,7 @@ example: } // go line by line from stdin or run once with input from flags - for stdinFilter := range getJsonsOrBlank() { + for stdinFilter := range getJsonsOrBlank(false) { filter := nostr.Filter{} if stdinFilter != "" { if err := easyjson.Unmarshal([]byte(stdinFilter), &filter); err != nil { diff --git a/spell.go b/spell.go index 7c94ce0..b4eaa7a 100644 --- a/spell.go +++ b/spell.go @@ -57,7 +57,7 @@ var spell = &cli.Command{ if c.Args().Len() == 0 { // check if we have input from stdin - for stdinEvent := range getJsonsOrBlank() { + for stdinEvent := range getJsonsOrBlank(false) { if stdinEvent == "{}" { break } diff --git a/validate.go b/validate.go index 8b966dc..404b34d 100644 --- a/validate.go +++ b/validate.go @@ -50,7 +50,7 @@ nak event -k 1 -p not_a_pubkey | nak validate return nil } - for stdinEvent := range getJsonsOrBlank() { + for stdinEvent := range getJsonsOrBlank(false) { if stdinEvent == "{}" && !isPiped() { // blank sentinel from getJsonsOrBlank(), use the arguments instead for _, arg := range c.Args().Slice() { diff --git a/verify.go b/verify.go index 27cf2a2..333eb5b 100644 --- a/verify.go +++ b/verify.go @@ -17,7 +17,7 @@ var verify = &cli.Command{ it outputs nothing if the verification is successful.`, DisableSliceFlagSeparator: true, Action: func(ctx context.Context, c *cli.Command) error { - for stdinEvent := range getJsonsOrBlank() { + for stdinEvent := range getJsonsOrBlank(false) { evt := nostr.Event{} if stdinEvent == "{}" && !isPiped() { // blank sentinel from getJsonsOrBlank(), use the argument instead