fix metal provider flag and env loading, and return error if provider not defined

This commit is contained in:
Mike Mason
2023-07-19 17:48:22 +00:00
parent 6c5073ba9b
commit 02c7895449
6 changed files with 45 additions and 0 deletions

View File

@@ -1,11 +1,23 @@
package emgql
import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.infratographer.com/x/viperx"
)
// Config provides configuration for connecting to the Equinix Metal API provider.
type Config struct {
// BaseURL is the baseurl to use when connecting to the Equinix Metal API Provider.
BaseURL string
}
// MustViperFlags registers command flags along with the viper bindings.
func MustViperFlags(v *viper.Viper, flags *pflag.FlagSet) {
flags.String("emgql-base-url", "", "Equinix Metal GraphQL Base URL")
viperx.MustBindFlag(v, "equinixmetal.emgql.baseurl", flags.Lookup("emgql-base-url"))
}
// Populated checks if any field has been populated.
func (c Config) Populated() bool {
return c.BaseURL != ""