mirror of
https://github.com/fiatjaf/nak.git
synced 2026-10-05 15:18:23 +00:00
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:
+1
-1
@@ -305,7 +305,7 @@ if any of the files are not found the command will fail, otherwise it will succe
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for input := range getJsonsOrBlank() {
|
for input := range getJsonsOrBlank(false) {
|
||||||
if input == "{}" {
|
if input == "{}" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ var count = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// go line by line from stdin or run once with input from flags
|
// 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{}
|
filter := nostr.Filter{}
|
||||||
if stdinFilter != "" {
|
if stdinFilter != "" {
|
||||||
if err := easyjson.Unmarshal([]byte(stdinFilter), &filter); err != nil {
|
if err := easyjson.Unmarshal([]byte(stdinFilter), &filter); err != nil {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func getEncodeSubcommandInput(args cli.Args, allowBlank bool) iter.Seq[string] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return func(yield func(string) bool) {
|
return func(yield func(string) bool) {
|
||||||
for jsonStr := range getJsonsOrBlank() {
|
for jsonStr := range getJsonsOrBlank(false) {
|
||||||
if jsonStr == "{}" {
|
if jsonStr == "{}" {
|
||||||
if allowBlank {
|
if allowBlank {
|
||||||
yield("")
|
yield("")
|
||||||
@@ -96,7 +96,7 @@ var encode = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasStdin := false
|
hasStdin := false
|
||||||
for jsonStr := range getJsonsOrBlank() {
|
for jsonStr := range getJsonsOrBlank(false) {
|
||||||
if jsonStr == "{}" {
|
if jsonStr == "{}" {
|
||||||
hasStdin = false
|
hasStdin = false
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -172,6 +172,11 @@ example:
|
|||||||
Usage: "ask before publishing the event",
|
Usage: "ask before publishing the event",
|
||||||
Category: CATEGORY_EXTRAS,
|
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
|
// hidden
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
@@ -442,7 +447,7 @@ example:
|
|||||||
return publishFlow(ctx, c, kr, evt, relays)
|
return publishFlow(ctx, c, kr, evt, relays)
|
||||||
}
|
}
|
||||||
|
|
||||||
for stdinEvent := range getJsonsOrBlank() {
|
for stdinEvent := range getJsonsOrBlank(c.Bool("github")) {
|
||||||
if err := handleEvent(stdinEvent); err != nil {
|
if err := handleEvent(stdinEvent); err != nil {
|
||||||
ctx = lineProcessingError(ctx, err.Error())
|
ctx = lineProcessingError(ctx, err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ example:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if there is no stdin we'll still get an empty object here
|
// 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
|
var evt nostr.Event
|
||||||
if err := easyjson.Unmarshal([]byte(evtj), &evt); err != nil {
|
if err := easyjson.Unmarshal([]byte(evtj), &evt); err != nil {
|
||||||
ctx = lineProcessingError(ctx, "invalid event: %s", err)
|
ctx = lineProcessingError(ctx, "invalid event: %s", err)
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ a decoupled key (if it has been created or received with "nak dekey" previously)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read event from stdin
|
// read event from stdin
|
||||||
for eventJSON := range getJsonsOrBlank() {
|
for eventJSON := range getJsonsOrBlank(false) {
|
||||||
if eventJSON == "{}" {
|
if eventJSON == "{}" {
|
||||||
continue
|
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
|
// read gift-wrapped event from stdin
|
||||||
for wrapJSON := range getJsonsOrBlank() {
|
for wrapJSON := range getJsonsOrBlank(false) {
|
||||||
if wrapJSON == "{}" {
|
if wrapJSON == "{}" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -70,7 +70,7 @@ func isPiped() bool {
|
|||||||
return is
|
return is
|
||||||
}
|
}
|
||||||
|
|
||||||
func getJsonsOrBlank() iter.Seq[string] {
|
func getJsonsOrBlank(github bool) iter.Seq[string] {
|
||||||
var curr strings.Builder
|
var curr strings.Builder
|
||||||
|
|
||||||
var finalJsonErr error
|
var finalJsonErr error
|
||||||
@@ -102,7 +102,7 @@ func getJsonsOrBlank() iter.Seq[string] {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hasStdin {
|
if !hasStdin && (!isPiped() || github) {
|
||||||
if !yield("{}") {
|
if !yield("{}") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ example:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// go line by line from stdin or run once with input from flags
|
// 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{}
|
filter := nostr.Filter{}
|
||||||
if stdinFilter != "" {
|
if stdinFilter != "" {
|
||||||
if err := easyjson.Unmarshal([]byte(stdinFilter), &filter); err != nil {
|
if err := easyjson.Unmarshal([]byte(stdinFilter), &filter); err != nil {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ var spell = &cli.Command{
|
|||||||
|
|
||||||
if c.Args().Len() == 0 {
|
if c.Args().Len() == 0 {
|
||||||
// check if we have input from stdin
|
// check if we have input from stdin
|
||||||
for stdinEvent := range getJsonsOrBlank() {
|
for stdinEvent := range getJsonsOrBlank(false) {
|
||||||
if stdinEvent == "{}" {
|
if stdinEvent == "{}" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ nak event -k 1 -p not_a_pubkey | nak validate
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for stdinEvent := range getJsonsOrBlank() {
|
for stdinEvent := range getJsonsOrBlank(false) {
|
||||||
if stdinEvent == "{}" && !isPiped() {
|
if stdinEvent == "{}" && !isPiped() {
|
||||||
// blank sentinel from getJsonsOrBlank(), use the arguments instead
|
// blank sentinel from getJsonsOrBlank(), use the arguments instead
|
||||||
for _, arg := range c.Args().Slice() {
|
for _, arg := range c.Args().Slice() {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ var verify = &cli.Command{
|
|||||||
it outputs nothing if the verification is successful.`,
|
it outputs nothing if the verification is successful.`,
|
||||||
DisableSliceFlagSeparator: true,
|
DisableSliceFlagSeparator: true,
|
||||||
Action: func(ctx context.Context, c *cli.Command) error {
|
Action: func(ctx context.Context, c *cli.Command) error {
|
||||||
for stdinEvent := range getJsonsOrBlank() {
|
for stdinEvent := range getJsonsOrBlank(false) {
|
||||||
evt := nostr.Event{}
|
evt := nostr.Event{}
|
||||||
if stdinEvent == "{}" && !isPiped() {
|
if stdinEvent == "{}" && !isPiped() {
|
||||||
// blank sentinel from getJsonsOrBlank(), use the argument instead
|
// blank sentinel from getJsonsOrBlank(), use the argument instead
|
||||||
|
|||||||
Reference in New Issue
Block a user