mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
94a3be3e6e
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/1749 Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: 4515f7f2c58b7f28645b2c5a5d9842aa7a844eae
28 lines
700 B
Go
28 lines
700 B
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/spf13/pflag"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// ViperEnvPrefix - Env prefix to be used in viper
|
|
const ViperEnvPrefix = "HASURA_GRAPHQL"
|
|
|
|
// ViperEnvReplacer - Env replacer to be used in viper
|
|
var ViperEnvReplacer = strings.NewReplacer(".", "_")
|
|
|
|
// BindPFlag - binds flag with viper along with env usage
|
|
func BindPFlag(v *viper.Viper, key string, f *pflag.Flag) {
|
|
err := v.BindPFlag(key, f)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "viper failed binding pflag: %v with error: %v \n", key, err)
|
|
}
|
|
key = ViperEnvReplacer.Replace(key)
|
|
key = strings.ToUpper(ViperEnvPrefix + "_" + key)
|
|
f.Usage = f.Usage + fmt.Sprintf(` (env "%s")`, key)
|
|
}
|