From 55707c26af51b0c10611b962037a6d833ecd4778 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Thu, 1 Oct 2026 17:48:34 -0300 Subject: [PATCH] nak relays --- main.go | 1 + relays.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 relays.go diff --git a/main.go b/main.go index 95a4b67..d7d5c41 100644 --- a/main.go +++ b/main.go @@ -102,6 +102,7 @@ var app = &cli.Command{ spell, profile, validateCmd, + relaysCmd, }, Version: version, Flags: combineFlags([][]cli.Flag{ diff --git a/relays.go b/relays.go new file mode 100644 index 0000000..7c2a58a --- /dev/null +++ b/relays.go @@ -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 + }, +}