support --nson flag on event.

This commit is contained in:
fiatjaf
2023-07-05 14:11:15 -03:00
parent 194e94ec9a
commit 3ace11d7b2
3 changed files with 14 additions and 5 deletions

View File

@@ -9,7 +9,9 @@ import (
"strings"
"time"
"github.com/mailru/easyjson"
"github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nson"
"github.com/urfave/cli/v2"
)
@@ -33,6 +35,10 @@ standalone:
Name: "envelope",
Usage: "print the event enveloped in a [\"EVENT\", ...] message ready to be sent to a relay",
},
&cli.BoolFlag{
Name: "nson",
Usage: "encode the event using NSON",
},
&cli.IntFlag{
Name: "kind",
Aliases: []string{"k"},
@@ -144,8 +150,11 @@ standalone:
if c.Bool("envelope") {
j, _ := json.Marshal([]any{"EVENT", evt})
result = string(j)
} else if c.Bool("nson") {
result, _ = nson.Marshal(&evt)
} else {
result = evt.String()
j, _ := easyjson.Marshal(&evt)
result = string(j)
}
fmt.Println(result)
}