Correct nak event behaviour if 0 lines received from an open stdin

Restored the original behaviour of outputting 0 events as per https://github.com/fiatjaf/nak/pull/81

To make it work like after the fix to https://github.com/fiatjaf/nak/issues/90 `--github` parameter should be passed.
This commit is contained in:
Lez
2026-09-27 13:35:56 -03:00
committed by fiatjaf
parent ec23f8593a
commit 30551476c5
11 changed files with 19 additions and 14 deletions
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -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
+6 -1
View File
@@ -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())
}
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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
}
+2 -2
View File
@@ -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
}
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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() {
+1 -1
View File
@@ -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