Skip to content

Commit

Permalink
Allow expiretiles_zoom to be set in config JSON (#261)
Browse files Browse the repository at this point in the history
Before this change, the default value for the -expiretiles-zoom
command-line flag (14) would always overwrite whatever value was set for
expiretiles_zoom in the config JSON. This change allows for four
options:

- No flag value, no config value: default value used
- No flag value, config value: config value used
- Flag value, no config value: flag value used
- Both flag and config value: flag value used

Fixes #181.
  • Loading branch information
flother authored Aug 23, 2022
1 parent b7e153b commit 20db391
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ func addBaseFlags(opts *Base, flags *flag.FlagSet) {
flags.StringVar(&opts.Schemas.Backup, "dbschema-backup", defaultSchemaBackup, "db schema for backups")
}

func isFlagActual(flags *flag.FlagSet, name string) bool {
found := false
flags.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}

func ParseImport(args []string) Import {
flags := flag.NewFlagSet("import", flag.ExitOnError)
opts := Import{}
Expand Down Expand Up @@ -254,6 +264,11 @@ func ParseDiffImport(args []string) (Base, []string) {
log.Fatal(err)
}

// If expiretiles-zoom hasn't been explicitly set on the command-line, use the
// value from config.json or fall back to the default value.
if !isFlagActual(flags, "expiretiles-zoom") {
flags.Set("expiretiles-zoom", "0")
}
err = opts.updateFromConfig()
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -292,6 +307,11 @@ func ParseRunImport(args []string) Base {
log.Fatal(err)
}

// If expiretiles-zoom hasn't been explicitly set on the command-line, use the
// value from config.json or fall back to the default value.
if !isFlagActual(flags, "expiretiles-zoom") {
flags.Set("expiretiles-zoom", "0")
}
err = opts.updateFromConfig()
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 20db391

Please sign in to comment.