add env variable KUBECONFORM_SCHEMA_LOCATION with comma-separated list of values

This commit is contained in:
Serhii Rudenko 2025-02-20 14:56:30 +02:00
parent 1bd44986dd
commit 31c3c42c9d

View file

@ -4,6 +4,7 @@ import (
"bytes"
"flag"
"fmt"
"os"
"regexp"
"strings"
)
@ -75,7 +76,7 @@ func splitCSV(csvStr string) map[string]struct{} {
// FromFlags retrieves kubeconform's runtime configuration from the command-line parameters
func FromFlags(progName string, args []string) (Config, string, error) {
var schemaLocationsParam, ignoreFilenamePatterns arrayParam
var skipKindsCSV, rejectKindsCSV string
var skipKindsCSV, rejectKindsCSV, envSchemaLocation string
flags := flag.NewFlagSet(progName, flag.ContinueOnError)
var buf bytes.Buffer
flags.SetOutput(&buf)
@ -113,6 +114,21 @@ func FromFlags(progName string, args []string) (Config, string, error) {
c.SchemaLocations = schemaLocationsParam
c.Files = flags.Args()
envSchemaLocation, _ = os.LookupEnv("KUBECONFORM_SCHEMA_LOCATION")
if envSchemaLocation != "" {
var kubeconformSchemaLocation []string
kubeconformSchemaLocation = strings.Split(envSchemaLocation, ",")
for _, s := range kubeconformSchemaLocation {
c.SchemaLocations = append(c.SchemaLocations, s)
}
}
if c.Verbose == true {
for i, s := range c.SchemaLocations {
fmt.Printf("Schema location %d: %s\n", i, s)
}
}
if c.Help {
flags.Usage()
}