2023-11-20 13:00:50 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-06-25 21:18:26 -04:00
|
|
|
"context"
|
2023-11-20 13:00:50 -05:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/nbd-wtf/go-nostr/nip11"
|
2024-06-25 21:18:26 -04:00
|
|
|
"github.com/urfave/cli/v3"
|
2023-11-20 13:00:50 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var relay = &cli.Command{
|
|
|
|
Name: "relay",
|
|
|
|
Usage: "gets the relay information document for the given relay, as JSON",
|
|
|
|
Description: `example:
|
2023-11-20 13:01:51 -05:00
|
|
|
nak relay nostr.wine`,
|
2023-11-20 13:00:50 -05:00
|
|
|
ArgsUsage: "<relay-url>",
|
2024-06-25 21:18:26 -04:00
|
|
|
Action: func(ctx context.Context, c *cli.Command) error {
|
2024-03-19 10:34:59 -04:00
|
|
|
for url := range getStdinLinesOrArguments(c.Args()) {
|
|
|
|
if url == "" {
|
|
|
|
return fmt.Errorf("specify the <relay-url>")
|
|
|
|
}
|
2023-11-20 13:00:50 -05:00
|
|
|
|
2024-06-25 21:18:26 -04:00
|
|
|
info, err := nip11.Fetch(ctx, url)
|
2024-03-19 10:34:59 -04:00
|
|
|
if err != nil {
|
2024-06-25 21:18:26 -04:00
|
|
|
lineProcessingError(ctx, "failed to fetch '%s' information document: %w", url, err)
|
2024-03-19 10:34:59 -04:00
|
|
|
continue
|
|
|
|
}
|
2023-11-20 13:00:50 -05:00
|
|
|
|
2024-03-19 10:34:59 -04:00
|
|
|
pretty, _ := json.MarshalIndent(info, "", " ")
|
|
|
|
stdout(string(pretty))
|
|
|
|
}
|
2023-11-20 13:00:50 -05:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|