Skip to content

Commit 6097029

Browse files
committed
select parser
1 parent b245d5e commit 6097029

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

cli/templatevariables.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,37 @@ func ParseUserVariableValues(varsFiles []string, variablesFile string, commandLi
6868
}
6969

7070
func parseVariableValuesFromVarsFiles(varsFiles []string) ([]codersdk.VariableValue, error) {
71-
panic("not implemented yet")
71+
var parsed []codersdk.VariableValue
72+
for _, varsFile := range varsFiles {
73+
content, err := os.ReadFile(varsFile)
74+
if err != nil {
75+
return nil, err
76+
}
77+
78+
var t []codersdk.VariableValue
79+
ext := filepath.Ext(varsFile)
80+
switch ext {
81+
case ".tfvars":
82+
t, err = parseVariableValuesFromHCL(content)
83+
case ".json":
84+
t, err = parseVariableValuesFromJSON(content)
85+
default:
86+
return nil, xerrors.Errorf("unsupported tfvars format: %s", ext)
87+
}
88+
if err != nil {
89+
return nil, err
90+
}
91+
92+
parsed = append(parsed, t...)
93+
}
94+
return parsed, nil
7295
}
7396

74-
func parseVariableValuesFromHCL(hcl string) ([]codersdk.VariableValue, error) {
97+
func parseVariableValuesFromHCL(hcl []byte) ([]codersdk.VariableValue, error) {
7598
panic("not implemented yet")
7699
}
77100

78-
func parseVariableValuesFromJSON(json string) ([]codersdk.VariableValue, error) {
101+
func parseVariableValuesFromJSON(json []byte) ([]codersdk.VariableValue, error) {
79102
panic("not implemented yet")
80103
}
81104

0 commit comments

Comments
 (0)