From 6d7df76b687f6602c31766e493dedbf49ddd43ff Mon Sep 17 00:00:00 2001 From: Lucas TESSON Date: Sat, 1 Jun 2024 14:14:51 +0200 Subject: [PATCH] fix: read configuration file iif set --- cmd/ctfd-setup/main.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/cmd/ctfd-setup/main.go b/cmd/ctfd-setup/main.go index a8cdfec..2769b89 100644 --- a/cmd/ctfd-setup/main.go +++ b/cmd/ctfd-setup/main.go @@ -573,19 +573,21 @@ func run(ctx *cli.Context) error { } // Read and unmarshal setup config file if any - f := ctx.String("file") - log.Info("getting configuration file", zap.String("file", f)) - if _, err := os.Stat(f); err == nil { - log.Info("configuration file found", zap.String("file", f)) - fd, err := os.Open(f) - if err != nil { - return errors.Wrapf(err, "opening file %s", f) - } - defer fd.Close() - dec := yaml.NewDecoder(fd) - dec.KnownFields(true) - if err := dec.Decode(&conf); err != nil { - return errors.Wrap(err, "unmarshalling configuration") + if ctx.IsSet("file") { + f := ctx.String("file") + log.Info("getting configuration file", zap.String("file", f)) + if _, err := os.Stat(f); err == nil { + fd, err := os.Open(f) + if err != nil { + return errors.Wrapf(err, "opening file %s", f) + } + defer fd.Close() + + dec := yaml.NewDecoder(fd) + dec.KnownFields(true) + if err := dec.Decode(&conf); err != nil { + return errors.Wrap(err, "unmarshalling configuration") + } } }