Skip to content

Commit

Permalink
[generate] Print relative variable names for dep variables (#450)
Browse files Browse the repository at this point in the history
* Print relative variable names for dep variables
* Use strings.Cut

Co-authored-by: Piotr Kazmierczak <[email protected]>
  • Loading branch information
angrycub and pkazmierczak authored Oct 25, 2023
1 parent 4ab0e83 commit b426f5b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sdk/pack/variables/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ func (v *Variable) Equal(ivp *Variable) bool {

func (v *Variable) AsOverrideString(pID pack.ID) string {
var out strings.Builder
out.WriteString(fmt.Sprintf(`# variable "%s"`, v.Name))

fqvn := strings.Join([]string{pID.String(), v.Name.String()}, ".")
_, rvn, _ := strings.Cut(fqvn, ".")

out.WriteString(fmt.Sprintf(`# variable "%s"`, rvn))
out.WriteByte('\n')
if v.hasDescription {
tmp := "description: " + v.Description
Expand All @@ -100,9 +104,9 @@ func (v *Variable) AsOverrideString(pID pack.ID) string {
}

if v.Value.Equals(v.Default).True() {
out.WriteString(fmt.Sprintf("#\n# %s=%s\n\n", v.Name, printDefault(v.Default)))
out.WriteString(fmt.Sprintf("#\n# %s=%s\n\n", rvn, printDefault(v.Default)))
} else {
out.WriteString(fmt.Sprintf("#\n%s=%s\n\n", v.Name, printDefault(v.Value)))
out.WriteString(fmt.Sprintf("#\n%s=%s\n\n", rvn, printDefault(v.Value)))
}

out.WriteString("\n")
Expand Down

0 comments on commit b426f5b

Please sign in to comment.