Skip to content

Commit

Permalink
fix: read configuration file iif set
Browse files Browse the repository at this point in the history
  • Loading branch information
pandatix committed Jun 1, 2024
1 parent 6f7cbb1 commit 6d7df76
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions cmd/ctfd-setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}

Expand Down

0 comments on commit 6d7df76

Please sign in to comment.