Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 08f84b6

Browse files
authoredApr 20, 2023
Merge branch 'coder:main' into main
2 parents 05b8034 + 38a6d54 commit 08f84b6

File tree

68 files changed

+2618
-1275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2618
-1275
lines changed
 

‎cli/cliui/output.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,35 @@ func (textFormat) AttachOptions(_ *clibase.OptionSet) {}
192192
func (textFormat) Format(_ context.Context, data any) (string, error) {
193193
return fmt.Sprintf("%s", data), nil
194194
}
195+
196+
// DataChangeFormat allows manipulating the data passed to an output format.
197+
// This is because sometimes the data needs to be manipulated before it can be
198+
// passed to the output format.
199+
// For example, you may want to pass something different to the text formatter
200+
// than what you pass to the json formatter.
201+
type DataChangeFormat struct {
202+
format OutputFormat
203+
change func(data any) (any, error)
204+
}
205+
206+
// ChangeFormatterData allows manipulating the data passed to an output
207+
// format.
208+
func ChangeFormatterData(format OutputFormat, change func(data any) (any, error)) *DataChangeFormat {
209+
return &DataChangeFormat{format: format, change: change}
210+
}
211+
212+
func (d *DataChangeFormat) ID() string {
213+
return d.format.ID()
214+
}
215+
216+
func (d *DataChangeFormat) AttachOptions(opts *clibase.OptionSet) {
217+
d.format.AttachOptions(opts)
218+
}
219+
220+
func (d *DataChangeFormat) Format(ctx context.Context, data any) (string, error) {
221+
newData, err := d.change(data)
222+
if err != nil {
223+
return "", err
224+
}
225+
return d.format.Format(ctx, newData)
226+
}

‎cli/templateedit_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,13 @@ func TestTemplateEdit(t *testing.T) {
167167

168168
// Test the cli command.
169169
displayName := "New Display Name 789"
170+
description := "New Description ABC"
170171
icon := "/icons/new-icon.png"
171172
cmdArgs := []string{
172173
"templates",
173174
"edit",
174175
template.Name,
176+
"--description", description,
175177
"--display-name", displayName,
176178
"--icon", icon,
177179
}
@@ -186,8 +188,8 @@ func TestTemplateEdit(t *testing.T) {
186188
// Assert that the template metadata changed.
187189
updated, err := client.Template(context.Background(), template.ID)
188190
require.NoError(t, err)
189-
assert.Equal(t, template.Name, updated.Name) // doesn't change
190-
assert.Equal(t, initialDescription, updated.Description) // doesn't change
191+
assert.Equal(t, template.Name, updated.Name) // doesn't change
192+
assert.Equal(t, description, updated.Description)
191193
assert.Equal(t, displayName, updated.DisplayName)
192194
assert.Equal(t, icon, updated.Icon)
193195
})
@@ -234,9 +236,9 @@ func TestTemplateEdit(t *testing.T) {
234236
require.NoError(t, err)
235237
// Properties don't change
236238
assert.Equal(t, template.Name, updated.Name)
237-
assert.Equal(t, template.Description, updated.Description)
238239
// These properties are removed, as the API considers it as "delete" request
239240
// See: https://github.com/coder/coder/issues/5066
241+
assert.Equal(t, "", updated.Description)
240242
assert.Equal(t, "", updated.Icon)
241243
assert.Equal(t, "", updated.DisplayName)
242244
})

‎coderd/apidoc/docs.go

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.