feat: Preview can now show presets and validate them#149
Merged
Conversation
Emyrk
reviewed
Jun 18, 2025
Emyrk
reviewed
Jun 18, 2025
SasSwart
commented
Jul 13, 2025
| EvalContext: block.Context().Inner(), | ||
| } | ||
|
|
||
| if tyAttr.IsNotNil() { |
Contributor
Author
There was a problem hiding this comment.
I found a nilpointer here during testing.
Emyrk
approved these changes
Jul 14, 2025
Comment on lines
+77
to
+104
| 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() | ||
| } |
Member
There was a problem hiding this comment.
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 { |
Member
There was a problem hiding this comment.
Suggested change
| switch true { | |
| switch { |
| "valid_parameter_name": ap(). | ||
| optVals("valid_option_value"), | ||
| }, | ||
| presets: func(t *testing.T, presets []types.Preset) { |
Member
There was a problem hiding this comment.
There is probably a way to make these assertions a bit more reusable. Fine for now though
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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