diff options
author | Fredrik Eriksson <fredrik-eriksson@users.noreply.github.com> | 2023-04-10 15:46:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 09:46:23 -0400 |
commit | cb1536471bcef4d78a3fe5cbd738b9f60fabbcc2 (patch) | |
tree | 781094bb72a5d745a2bcc86f0b3b0f697b0256ce | |
parent | f9d6092cfe235e0fbdbb7513b456713b8b0e9349 (diff) | |
download | gitea-cb1536471bcef4d78a3fe5cbd738b9f60fabbcc2.tar.gz gitea-cb1536471bcef4d78a3fe5cbd738b9f60fabbcc2.zip |
Add --quiet option to gitea dump (#22969)
Fixes: #19687
The --quiet options to gitea dump silences informational and less
important messages, but will still log warnings and errors to console.
Very useful in combination with cron backups and '-f -'.
Since --verbose and --quiet are incompatible with each other I made it
an error to specify both. To get the error message to be printed to
stderr I had to make this test after the NewServices()-call, which is
why there are three new blocks of code instead of two.
-rw-r--r-- | cmd/dump.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/cmd/dump.go b/cmd/dump.go index 19589caa75..309bd01f66 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -112,6 +112,10 @@ It can be used for backup and capture Gitea server image to send to maintainer`, Name: "verbose, V", Usage: "Show process details", }, + cli.BoolFlag{ + Name: "quiet, q", + Usage: "Only display warnings and errors", + }, cli.StringFlag{ Name: "tempdir, t", Value: os.TempDir(), @@ -192,12 +196,25 @@ func runDump(ctx *cli.Context) error { if _, err := setting.CfgProvider.Section("log.console").NewKey("STDERR", "true"); err != nil { fatal("Setting console logger to stderr failed: %v", err) } + + // Set loglevel to Warn if quiet-mode is requested + if ctx.Bool("quiet") { + if _, err := setting.CfgProvider.Section("log.console").NewKey("LEVEL", "Warn"); err != nil { + fatal("Setting console log-level failed: %v", err) + } + } + if !setting.InstallLock { log.Error("Is '%s' really the right config path?\n", setting.CustomConf) return fmt.Errorf("gitea is not initialized") } setting.LoadSettings() // cannot access session settings otherwise + verbose := ctx.Bool("verbose") + if verbose && ctx.Bool("quiet") { + return fmt.Errorf("--quiet and --verbose cannot both be set") + } + stdCtx, cancel := installSignals() defer cancel() @@ -223,7 +240,6 @@ func runDump(ctx *cli.Context) error { return err } - verbose := ctx.Bool("verbose") var iface interface{} if fileName == "-" { iface, err = archiver.ByExtension(fmt.Sprintf(".%s", outType)) |