package main import ( "github.com/spf13/pflag" "github.com/spf13/viper" ) const ( configPort = "Port" defaultPort = 3333 flagPort = "port" configTLSEnabled = "TLS.Enabled" defaultTLSEnabled = true flagTLSEnabled = "tls-enabled" configTLSCert = "TLS.Cert" defaultTLSCert = "" flagTLSCert = "tls-cert" configTLSKey = "TLS.Key" defaultTLSKey = "" flagTLSKey = "tls-key" ) // BindClientFlags declares client-related flags and config options in the specified *pflag.FlagSet func BindFlags(set *pflag.FlagSet) error { // Credentials -> seulement par config set.Int(flagPort, defaultPort, "User interface port") if err := viper.BindPFlag(configPort, set.Lookup(flagPort)); err != nil { return err } set.Bool(flagTLSEnabled, defaultTLSEnabled, "User interface TLS state") if err := viper.BindPFlag(configTLSEnabled, set.Lookup(flagTLSEnabled)); err != nil { return err } set.String(flagTLSKey, defaultTLSKey, "User interface TLS private key (or path to file)") if err := viper.BindPFlag(configTLSKey, set.Lookup(flagTLSKey)); err != nil { return err } set.String(flagTLSCert, defaultTLSCert, "User interface TLS certificate (or path to file)") if err := viper.BindPFlag(configTLSCert, set.Lookup(flagTLSCert)); err != nil { return err } return nil }