From 5afdce2672803ddc052bfcb01c7a3c011a1ef38e Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 21 Jun 2026 08:26:08 -0300 Subject: [PATCH] profile: flags to print only specific things. --- README.md | 3 +++ profile.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/README.md b/README.md index 2501768..da613f0 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,9 @@ relays: wss://140.f7z.io (write) wss://r.f7z.io (read/write) follows: 1051 +~> +~> nak profile f7z.io --name +PABLOF7z ``` ### sign an event using a bunker provider (amber, promenade etc) diff --git a/profile.go b/profile.go index 3eae0f4..77ce4d5 100644 --- a/profile.go +++ b/profile.go @@ -3,6 +3,8 @@ package main import ( "context" + stdjson "encoding/json" + "fiatjaf.com/nostr/nip19" "github.com/fatih/color" "github.com/urfave/cli/v3" @@ -16,6 +18,24 @@ var profile = &cli.Command{ example usage: nak profile npub1h8spmtw9m2huyv6v2j2qd5zv956z2zdugl6mgx02f2upffwpm3nqv0j4ps nak profile user@example.com`, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "name", + Usage: "print only the name", + }, + &cli.BoolFlag{ + Name: "picture", + Usage: "print only the picture URL", + }, + &cli.BoolFlag{ + Name: "about", + Usage: "print only the about text", + }, + &cli.BoolFlag{ + Name: "metadata", + Usage: "print the profile metadata as JSON", + }, + }, ArgsUsage: "[pubkey]", Action: func(ctx context.Context, c *cli.Command) error { for pubkeyInput := range getStdinLinesOrArguments(c.Args()) { @@ -27,6 +47,24 @@ example usage: pm := sys.FetchProfileMetadata(ctx, pk) + if c.Bool("name") { + stdout(pm.Name) + continue + } + if c.Bool("picture") { + stdout(pm.Picture) + continue + } + if c.Bool("about") { + stdout(pm.About) + continue + } + if c.Bool("metadata") { + j, _ := stdjson.Marshal(pm) + stdout(string(j)) + continue + } + npub := nip19.EncodeNpub(pk) stdout(colors.bold("pubkey (hex):"), pk.Hex()) stdout(colors.bold("npub:"), color.HiCyanString(npub))