Skip to content

Commit cb15364

Browse files
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.
1 parent f9d6092 commit cb15364

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

cmd/dump.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ It can be used for backup and capture Gitea server image to send to maintainer`,
112112
Name: "verbose, V",
113113
Usage: "Show process details",
114114
},
115+
cli.BoolFlag{
116+
Name: "quiet, q",
117+
Usage: "Only display warnings and errors",
118+
},
115119
cli.StringFlag{
116120
Name: "tempdir, t",
117121
Value: os.TempDir(),
@@ -192,12 +196,25 @@ func runDump(ctx *cli.Context) error {
192196
if _, err := setting.CfgProvider.Section("log.console").NewKey("STDERR", "true"); err != nil {
193197
fatal("Setting console logger to stderr failed: %v", err)
194198
}
199+
200+
// Set loglevel to Warn if quiet-mode is requested
201+
if ctx.Bool("quiet") {
202+
if _, err := setting.CfgProvider.Section("log.console").NewKey("LEVEL", "Warn"); err != nil {
203+
fatal("Setting console log-level failed: %v", err)
204+
}
205+
}
206+
195207
if !setting.InstallLock {
196208
log.Error("Is '%s' really the right config path?\n", setting.CustomConf)
197209
return fmt.Errorf("gitea is not initialized")
198210
}
199211
setting.LoadSettings() // cannot access session settings otherwise
200212

213+
verbose := ctx.Bool("verbose")
214+
if verbose && ctx.Bool("quiet") {
215+
return fmt.Errorf("--quiet and --verbose cannot both be set")
216+
}
217+
201218
stdCtx, cancel := installSignals()
202219
defer cancel()
203220

@@ -223,7 +240,6 @@ func runDump(ctx *cli.Context) error {
223240
return err
224241
}
225242

226-
verbose := ctx.Bool("verbose")
227243
var iface interface{}
228244
if fileName == "-" {
229245
iface, err = archiver.ByExtension(fmt.Sprintf(".%s", outType))

0 commit comments

Comments
 (0)