nak relays

This commit is contained in:
fiatjaf
2026-10-01 17:48:34 -03:00
parent 5f28b21cbd
commit 55707c26af
2 changed files with 59 additions and 0 deletions
+1
View File
@@ -102,6 +102,7 @@ var app = &cli.Command{
spell,
profile,
validateCmd,
relaysCmd,
},
Version: version,
Flags: combineFlags([][]cli.Flag{
+58
View File
@@ -0,0 +1,58 @@
package main
import (
"context"
"github.com/urfave/cli/v3"
)
var relaysCmd = &cli.Command{
Name: "relays",
Usage: "prints the nip65 relays for a given pubkey, one relay per line",
ArgsUsage: "[pubkey]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "inbox",
Aliases: []string{"read"},
Usage: "only print relays marked as inbox/read",
},
&cli.BoolFlag{
Name: "outbox",
Aliases: []string{"write"},
Usage: "only print relays marked as outbox/write",
},
},
Action: func(ctx context.Context, c *cli.Command) error {
wantInbox := c.Bool("inbox")
wantOutbox := c.Bool("outbox")
for pubkeyInput := range getStdinLinesOrArguments(c.Args()) {
pk, err := parsePubKeyForCommand(ctx, c, pubkeyInput)
if err != nil {
ctx = lineProcessingError(ctx, "invalid pubkey '%s': %s", pubkeyInput, err)
continue
}
relayList := sys.FetchRelayList(ctx, pk)
for _, rl := range relayList.Items {
if wantInbox && wantOutbox {
if !(rl.Inbox && rl.Outbox) {
continue
}
} else if wantInbox {
if !rl.Inbox {
continue
}
} else if wantOutbox {
if !rl.Outbox {
continue
}
}
stdout(rl.URL)
}
}
exitIfLineProcessingError(ctx)
return nil
},
}