diff --git a/Dockerfile b/Dockerfile index 58bd37f..1a56be2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,4 +34,4 @@ RUN \ curl -SLf https://github.com/docker/compose/releases/download/v${COMPOSE_VERSION}/docker-compose-linux-${DOWNLOAD_ARCH} -o /usr/local/lib/docker/cli-plugins/docker-compose && \ chmod +x /usr/local/lib/docker/cli-plugins/docker-compose COPY --from=builder /go/src/app/main /usr/local/bin/docker-compose-watcher -CMD ["docker-compose-watcher", "-once=0", "-printSettings"] +CMD ["docker-compose-watcher", "-printSettings"] diff --git a/src/settings.go b/src/settings.go index 66b7909..9298b3a 100644 --- a/src/settings.go +++ b/src/settings.go @@ -5,7 +5,6 @@ import ( "log" "os" "strconv" - "strings" ) // Settings holds the program runtime configuration @@ -34,7 +33,7 @@ func ReadSettings() { s.boolFlagEnv(&s.Dry, "dry", "DRY", false, "dry run: check and pull, but don't restart") s.boolFlagEnv(&s.Help, "help", "HELP", false, "print usage instructions") s.int64FlagEnv(&s.Interval, "interval", "INTERVAL", 60, "interval in minutes between runs") - s.boolFlagEnv(&s.Once, "once", "ONCE", true, "run once and exit, do not run in background") + s.boolFlagEnv(&s.Once, "once", "ONCE", false, "run once and exit, do not run in background") s.boolFlagEnv(&s.PrintSettings, "printSettings", "PRINT_SETTINGS", false, "print used settings") s.stringFlagEnv(&s.UpdateLog, "updateLog", "UPDATE_LOG", "", "update log file") //s.boolFlagEnv(&s.CompleteStop, "completeStop", "COMPLETE_STOP", false, "Restart all services in docker-compose.yml (even unmanaged) after a new image is pulled") @@ -51,23 +50,32 @@ func ReadSettings() { func (settings *Settings) boolFlagEnv(p *bool, name string, env string, value bool, usage string) { flag.BoolVar(p, name, value, usage+" (env "+env+")") val := os.Getenv(env) - if (val != "") && (val != "0") && (strings.ToLower(val) != "false") { - *p = true + if val != "" { + b, err := strconv.ParseBool(val) + if err != nil { + log.Fatal(err) + } + *p = b } } func (settings *Settings) int64FlagEnv(p *int64, name string, env string, value int64, usage string) { flag.Int64Var(p, name, value, usage+" (env "+env+")") - if os.Getenv(env) != "" { - i, _ := strconv.ParseInt(os.Getenv(env), 10, 0) + val := os.Getenv(env) + if val != "" { + i, err := strconv.ParseInt(val, 10, 0) + if err != nil { + log.Fatal(err) + } *p = i } } func (settings *Settings) stringFlagEnv(p *string, name string, env string, value string, usage string) { flag.StringVar(p, name, value, usage+" (env "+env+")") - if os.Getenv(env) != "" { - *p = os.Getenv(env) + val := os.Getenv(env) + if val != "" { + *p = val } }