-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Preview can now show presets and validate them #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
EvalContext: block.Context().Inner(), | ||
} | ||
|
||
if tyAttr.IsNotNil() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a nilpointer here during testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
func Presets(writer io.Writer, presets []types.Preset, files map[string]*hcl.File) { | ||
tableWriter := table.NewWriter() | ||
tableWriter.SetStyle(table.StyleLight) | ||
tableWriter.Style().Options.SeparateColumns = false | ||
row := table.Row{"Preset"} | ||
tableWriter.AppendHeader(row) | ||
for _, p := range presets { | ||
tableWriter.AppendRow(table.Row{ | ||
fmt.Sprintf("%s\n%s", p.Name, formatPresetParameters(p.Parameters)), | ||
}) | ||
if hcl.Diagnostics(p.Diagnostics).HasErrors() { | ||
var out bytes.Buffer | ||
WriteDiagnostics(&out, files, hcl.Diagnostics(p.Diagnostics)) | ||
tableWriter.AppendRow(table.Row{out.String()}) | ||
} | ||
|
||
tableWriter.AppendSeparator() | ||
} | ||
_, _ = fmt.Fprintln(writer, tableWriter.Render()) | ||
} | ||
|
||
func formatPresetParameters(presetParameters map[string]string) string { | ||
var str strings.Builder | ||
for presetParamName, PresetParamValue := range presetParameters { | ||
_, _ = str.WriteString(fmt.Sprintf("%s = %s\n", presetParamName, PresetParamValue)) | ||
} | ||
return str.String() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. The preview cli is very much a dev tool still. 👍
blocks := mod.GetDatasByType(types.BlockTypePreset) | ||
for _, block := range blocks { | ||
preset := extract.PresetFromBlock(block) | ||
switch true { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch true { | |
switch { |
"valid_parameter_name": ap(). | ||
optVals("valid_option_value"), | ||
}, | ||
presets: func(t *testing.T, presets []types.Preset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is probably a way to make these assertions a bit more reusable. Fine for now though
This PR provides a mechanism to "lint" presets to ensure that they refer to parameters that actually exist and define values that are actually valid for those parameters.
Relates to: coder/coder#17333