Files
zeekay fb0e4ce424 fork: traefik/paerser -> hanzoai/ingress-parser
Rebrand module path, DefaultNamePrefix TRAEFIK_ -> INGRESS_,
DefaultRootName traefik -> ingress, config paths /etc/traefik -> /etc/ingress.
All 7 packages pass tests.
2026-03-19 02:57:11 -07:00

33 lines
765 B
Go

package cli
import (
"fmt"
"os"
"github.com/hanzoai/ingress-parser/env"
)
// EnvLoader loads a configuration from all the environment variables prefixed with Prefix (default: "INGRESS_").
type EnvLoader struct {
Prefix string
}
// Load loads the command's configuration from the environment variables.
func (e *EnvLoader) Load(_ []string, cmd *Command) (bool, error) {
prefix := env.DefaultNamePrefix
if e.Prefix != "" {
prefix = e.Prefix
}
vars := env.FindPrefixedEnvVars(os.Environ(), prefix, cmd.Configuration)
if len(vars) == 0 {
return false, nil
}
if err := env.Decode(vars, prefix, cmd.Configuration); err != nil {
return false, fmt.Errorf("failed to decode configuration from environment variables: %w ", err)
}
return true, nil
}