-q to silence stderr, -qq to silence everything.

This commit is contained in:
fiatjaf
2024-01-24 22:38:51 -03:00
parent 3f7089e27e
commit 14b69f36cf
9 changed files with 26 additions and 22 deletions

17
main.go
View File

@@ -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)
}
}