From 43a3e5f40d57d5d68f5f81e610044b23a9a90040 Mon Sep 17 00:00:00 2001 From: fiatjaf <fiatjaf@gmail.com> Date: Tue, 18 Feb 2025 18:19:36 -0300 Subject: [PATCH] event: support reading --content from a file if the name starts with @. --- event.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/event.go b/event.go index 8d32bc1..d30bec8 100644 --- a/event.go +++ b/event.go @@ -8,11 +8,11 @@ import ( "strings" "time" - "github.com/urfave/cli/v3" "github.com/mailru/easyjson" "github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr/nip13" "github.com/nbd-wtf/go-nostr/nip19" + "github.com/urfave/cli/v3" ) const ( @@ -94,7 +94,7 @@ example: &cli.StringFlag{ Name: "content", Aliases: []string{"c"}, - Usage: "event content", + Usage: "event content (if it starts with an '@' will read from a file)", DefaultText: "hello from the nostr army knife", Value: "", Category: CATEGORY_EVENT_FIELDS, @@ -179,7 +179,16 @@ example: } if c.IsSet("content") { - evt.Content = c.String("content") + content := c.String("content") + if strings.HasPrefix(content, "@") { + filedata, err := os.ReadFile(content[1:]) + if err != nil { + return fmt.Errorf("failed to read file '%s' for content: %w", content[1:], err) + } + evt.Content = string(filedata) + } else { + evt.Content = content + } mustRehashAndResign = true } else if evt.Content == "" && evt.Kind == 1 { evt.Content = "hello from the nostr army knife"