From 9f8b8e9caddc3cb5cb238ac9938a6830bb1079d9 Mon Sep 17 00:00:00 2001 From: Fred Heinecke Date: Wed, 6 Nov 2024 23:28:32 +0000 Subject: [PATCH] env-loader: Allow for providing environments directory via arg --- tools/env-loader/cmd/env-loader.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tools/env-loader/cmd/env-loader.go b/tools/env-loader/cmd/env-loader.go index e306edcd..4eddfb46 100644 --- a/tools/env-loader/cmd/env-loader.go +++ b/tools/env-loader/cmd/env-loader.go @@ -31,15 +31,21 @@ import ( const EnvVarPrefix = "ENV_LOADER_" type config struct { - Environment string - ValueSets []string - Values []string - Writer string + EnvironmentsDirectory string + Environment string + ValueSets []string + Values []string + Writer string } func parseCLI() *config { c := &config{} + kingpin.Flag("environments-directory", "Path to the directory containing all environments, defaulting to the repo root"). + Short('d'). + Envar(EnvVarPrefix + "ENVIRONMENT"). + StringVar(&c.EnvironmentsDirectory) + kingpin.Flag("environment", "Name of the environment containing the values to load"). Envar(EnvVarPrefix + "ENVIRONMENT"). Short('e'). @@ -69,7 +75,14 @@ func parseCLI() *config { func run(c *config) error { // Load in values - envValues, err := envloader.LoadEnvironmentValues(c.Environment, c.ValueSets) + var envValues map[string]string + var err error + if c.EnvironmentsDirectory != "" { + envValues, err = envloader.LoadEnvironmentValuesInDirectory(c.EnvironmentsDirectory, c.Environment, c.ValueSets) + } else { + envValues, err = envloader.LoadEnvironmentValues(c.Environment, c.ValueSets) + } + if err != nil { return trace.Wrap(err, "failed to load all environment values") }