Skip to content

Commit

Permalink
use OS package from env map
Browse files Browse the repository at this point in the history
Signed-off-by: satyazzz123 <[email protected]>
  • Loading branch information
satyazzz123 committed Jan 24, 2024
1 parent 2279bb9 commit 90383b8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/edit/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,26 @@ func constructOptions(resourceList *yaml.RNode) (*options.RunOptions, error) {

// getEnvMapOptionKCLValue retrieves the environment map from the KCL 'option("env")' function.
func getEnvMapOptionKCLValue(resourceList *yaml.RNode) (string, error) {
v, err := resourceList.Pipe(yaml.Lookup("option", "env"))

envMap := make(map[string]string)
env := os.Environ()
for _, e := range env {
pair := strings.SplitN(e, "=", 2)
envMap[pair[0]] = pair[1]
}

envMapInterface := make(map[string]interface{})
for k, v := range envMap {
envMapInterface[k] = v
}

v, err := yaml.FromMap(envMapInterface)
if err != nil {
return "", errors.Wrap(err)
}

envMapOptionKCLValue, err := ToKCLValueString(v, "{}")
// 4. Convert the YAML RNode to its KCL value string representation.
envMapOptionKCLValue, err := ToKCLValueString(v, emptyConfig)
if err != nil {
return "", errors.Wrap(err)
}
Expand Down

0 comments on commit 90383b8

Please sign in to comment.