count: support reading filters from stdin like req.

This commit is contained in:
fiatjaf
2026-02-12 14:34:24 -03:00
parent 1b380dea9a
commit 037e8efcc6
+12 -1
View File
@@ -9,13 +9,14 @@ import (
"fiatjaf.com/nostr"
"fiatjaf.com/nostr/nip45"
"fiatjaf.com/nostr/nip45/hyperloglog"
"github.com/mailru/easyjson"
"github.com/urfave/cli/v3"
)
var count = &cli.Command{
Name: "count",
Usage: "generates encoded COUNT messages and optionally use them to talk to relays",
Description: `outputs a nip45 request (the flags are mostly the same as 'nak req').`,
Description: `like 'nak req', but does a "COUNT" call instead. Will attempt to perform HyperLogLog aggregation if more than one relay is specified.`,
DisableSliceFlagSeparator: true,
Flags: reqFilterFlags,
ArgsUsage: "[relay...]",
@@ -37,7 +38,15 @@ var count = &cli.Command{
}
}
// go line by line from stdin or run once with input from flags
for stdinFilter := range getJsonsOrBlank() {
filter := nostr.Filter{}
if stdinFilter != "" {
if err := easyjson.Unmarshal([]byte(stdinFilter), &filter); err != nil {
ctx = lineProcessingError(ctx, "invalid filter '%s' received from stdin: %s", stdinFilter, err)
continue
}
}
if err := applyFlagsToFilter(c, &filter); err != nil {
return err
@@ -82,7 +91,9 @@ var count = &cli.Command{
result = string(j)
stdout(result)
}
}
exitIfLineProcessingError(ctx)
return nil
},
}