1
0
mirror of https://github.com/fiatjaf/nak.git synced 2025-07-29 08:18:28 -04:00

event: support reading --content from a file if the name starts with @.

This commit is contained in:
fiatjaf
2025-02-18 18:19:36 -03:00
parent 707e5b3918
commit 43a3e5f40d

@@ -8,11 +8,11 @@ import (
"strings" "strings"
"time" "time"
"github.com/urfave/cli/v3"
"github.com/mailru/easyjson" "github.com/mailru/easyjson"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip13" "github.com/nbd-wtf/go-nostr/nip13"
"github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip19"
"github.com/urfave/cli/v3"
) )
const ( const (
@@ -94,7 +94,7 @@ example:
&cli.StringFlag{ &cli.StringFlag{
Name: "content", Name: "content",
Aliases: []string{"c"}, 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", DefaultText: "hello from the nostr army knife",
Value: "", Value: "",
Category: CATEGORY_EVENT_FIELDS, Category: CATEGORY_EVENT_FIELDS,
@@ -179,7 +179,16 @@ example:
} }
if c.IsSet("content") { 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 mustRehashAndResign = true
} else if evt.Content == "" && evt.Kind == 1 { } else if evt.Content == "" && evt.Kind == 1 {
evt.Content = "hello from the nostr army knife" evt.Content = "hello from the nostr army knife"