diff --git a/cmd/root.go b/cmd/root.go index d19e5c4..9899ccc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -101,3 +101,15 @@ func initLogger() { log.SetLevel(lvl) } + +func mapEnvVars(envs map[string]string, cmd *cobra.Command) { + for env, flag := range envs { + flag := cmd.Flags().Lookup(flag) + flag.Usage = fmt.Sprintf("%v [env %v]", flag.Usage, env) + if value := os.Getenv(env); value != "" { + if err := flag.Value.Set(value); err != nil { + log.Error(err) + } + } + } +} diff --git a/cmd/server.go b/cmd/server.go index 4aa851e..4cb2beb 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -15,7 +15,6 @@ package cmd import ( "context" - "fmt" "net/http" "os" "os/signal" @@ -134,13 +133,5 @@ func init() { "PHP_FPM_FIX_PROCESS_COUNT": "phpfpm.fix-process-count", } - for env, flag := range envs { - flag := serverCmd.Flags().Lookup(flag) - flag.Usage = fmt.Sprintf("%v [env %v]", flag.Usage, env) - if value := os.Getenv(env); value != "" { - if err := flag.Value.Set(value); err != nil { - log.Error(err) - } - } - } + mapEnvVars(envs, serverCmd) }