mirror of
https://github.com/fiatjaf/nak.git
synced 2024-11-22 08:19:06 -05:00
-q to silence stderr, -qq to silence everything.
This commit is contained in:
parent
3f7089e27e
commit
14b69f36cf
2
count.go
2
count.go
|
@ -139,7 +139,7 @@ var count = &cli.Command{
|
|||
var result string
|
||||
j, _ := json.Marshal([]any{"COUNT", "nak", filter})
|
||||
result = string(j)
|
||||
fmt.Println(result)
|
||||
stdout(result)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
|
@ -68,7 +67,7 @@ var decode = &cli.Command{
|
|||
continue
|
||||
}
|
||||
|
||||
fmt.Println(decodeResult.JSON())
|
||||
stdout(decodeResult.JSON())
|
||||
|
||||
}
|
||||
|
||||
|
|
12
encode.go
12
encode.go
|
@ -36,7 +36,7 @@ var encode = &cli.Command{
|
|||
}
|
||||
|
||||
if npub, err := nip19.EncodePublicKey(target); err == nil {
|
||||
fmt.Println(npub)
|
||||
stdout(npub)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ var encode = &cli.Command{
|
|||
}
|
||||
|
||||
if npub, err := nip19.EncodePrivateKey(target); err == nil {
|
||||
fmt.Println(npub)
|
||||
stdout(npub)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ var encode = &cli.Command{
|
|||
}
|
||||
|
||||
if npub, err := nip19.EncodeProfile(target, relays); err == nil {
|
||||
fmt.Println(npub)
|
||||
stdout(npub)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ var encode = &cli.Command{
|
|||
}
|
||||
|
||||
if npub, err := nip19.EncodeEvent(target, relays, author); err == nil {
|
||||
fmt.Println(npub)
|
||||
stdout(npub)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ var encode = &cli.Command{
|
|||
}
|
||||
|
||||
if npub, err := nip19.EncodeEntity(pubkey, kind, d, relays); err == nil {
|
||||
fmt.Println(npub)
|
||||
stdout(npub)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ var encode = &cli.Command{
|
|||
}
|
||||
|
||||
if note, err := nip19.EncodeNote(target); err == nil {
|
||||
fmt.Println(note)
|
||||
stdout(note)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
|
2
event.go
2
event.go
|
@ -226,7 +226,7 @@ example:
|
|||
j, _ := easyjson.Marshal(&evt)
|
||||
result = string(j)
|
||||
}
|
||||
fmt.Println(result)
|
||||
stdout(result)
|
||||
|
||||
// publish to relays
|
||||
if len(relays) > 0 {
|
||||
|
|
4
fetch.go
4
fetch.go
|
@ -1,8 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nip19"
|
||||
sdk "github.com/nbd-wtf/nostr-sdk"
|
||||
|
@ -93,7 +91,7 @@ var fetch = &cli.Command{
|
|||
}
|
||||
|
||||
for ie := range pool.SubManyEose(c.Context, relays, nostr.Filters{filter}) {
|
||||
fmt.Println(ie.Event)
|
||||
stdout(ie.Event)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ var log = func(msg string, args ...any) {
|
|||
fmt.Fprintf(os.Stderr, msg, args...)
|
||||
}
|
||||
|
||||
var stdout = fmt.Println
|
||||
|
||||
func isPiped() bool {
|
||||
stat, _ := os.Stdin.Stat()
|
||||
return stat.Mode()&os.ModeCharDevice == 0
|
||||
|
|
17
main.go
17
main.go
|
@ -1,12 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var q int
|
||||
|
||||
var app = &cli.App{
|
||||
Name: "nak",
|
||||
Suggest: true,
|
||||
|
@ -25,12 +26,16 @@ var app = &cli.App{
|
|||
},
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "silent",
|
||||
Usage: "do not print logs and info messages to stderr",
|
||||
Aliases: []string{"s"},
|
||||
Name: "quiet",
|
||||
Usage: "do not print logs and info messages to stderr, use -qq to also not print anything to stdout",
|
||||
Count: &q,
|
||||
Aliases: []string{"q"},
|
||||
Action: func(ctx *cli.Context, b bool) error {
|
||||
if b {
|
||||
if q >= 1 {
|
||||
log = func(msg string, args ...any) {}
|
||||
if q >= 2 {
|
||||
stdout = func(a ...any) (int, error) { return 0, nil }
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
@ -40,7 +45,7 @@ var app = &cli.App{
|
|||
|
||||
func main() {
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fmt.Println(err)
|
||||
stdout(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
2
relay.go
2
relay.go
|
@ -31,7 +31,7 @@ var relay = &cli.Command{
|
|||
}
|
||||
|
||||
pretty, _ := json.MarshalIndent(info, "", " ")
|
||||
fmt.Println(string(pretty))
|
||||
stdout(string(pretty))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
4
req.go
4
req.go
|
@ -231,7 +231,7 @@ example:
|
|||
fn = pool.SubMany
|
||||
}
|
||||
for ie := range fn(c.Context, relayUrls, nostr.Filters{filter}) {
|
||||
fmt.Println(ie.Event)
|
||||
stdout(ie.Event)
|
||||
}
|
||||
} else {
|
||||
// no relays given, will just print the filter
|
||||
|
@ -243,7 +243,7 @@ example:
|
|||
result = string(j)
|
||||
}
|
||||
|
||||
fmt.Println(result)
|
||||
stdout(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user