Skip to content

Commit

Permalink
simplify env expansion
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Bandy <[email protected]>
Signed-off-by: Shawn O'Dell <[email protected]>
  • Loading branch information
so-jelly and cbandy committed Jan 22, 2023
1 parent 6e64c5d commit b9e4e45
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions pkg/test/utils/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"os"
"reflect"
"strings"
)

// Translate traverses an arbitrary struct and translates all strings it encounters
Expand All @@ -13,7 +12,7 @@ import (
//
// The MIT License (MIT)
//
// Copyright (c) 2014 Heye Vöcking
// # Copyright (c) 2014 Heye Vöcking
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -95,14 +94,7 @@ func translateRecursive(copy, original reflect.Value) {

// If it is a string translate it (yay finally we're doing what we came for)
case reflect.String:
translatedString := original.Interface().(string)
if strings.HasPrefix(translatedString, "$") {
variable := translatedString[1:]
if val, ok := os.LookupEnv(variable); ok {
translatedString = val
}
}
copy.SetString(translatedString)
copy.SetString(os.ExpandEnv(original.Interface().(string)))

// And everything else will simply be taken from the original
default:
Expand Down

0 comments on commit b9e4e45

Please sign in to comment.