-
Notifications
You must be signed in to change notification settings - Fork 905
feat: Implement parameters list + more template list columns #2359
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
- Allow more columns on template list
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.
someone with more Go experience should review but 👍 from the FE. BTW, if you merge main
in again, that chromatic CI check should clear up.
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.
This looks really useful!
cli/parameterslist.go
Outdated
"github.com/google/uuid" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/spf13/cobra" |
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.
nit: imports
func displayParameters(filterColumns []string, params ...codersdk.Parameter) string { | ||
tableWriter := cliui.Table() | ||
header := table.Row{"id", "scope", "scope id", "name", "source scheme", "destination scheme", "created at", "updated at"} | ||
tableWriter.AppendHeader(header) | ||
tableWriter.SetColumnConfigs(cliui.FilterTableColumns(header, filterColumns)) | ||
tableWriter.SortBy([]table.SortBy{{ | ||
Name: "name", | ||
}}) | ||
for _, param := range params { | ||
tableWriter.AppendRow(table.Row{ | ||
param.ID.String(), | ||
param.Scope, | ||
param.ScopeID.String(), | ||
param.Name, | ||
param.SourceScheme, | ||
param.DestinationScheme, | ||
param.CreatedAt, | ||
param.UpdatedAt, | ||
}) | ||
} | ||
return tableWriter.Render() | ||
} |
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 like this approach of abstracting the presentation logic from the command logic; makes it more re-usable later.
func displayTemplates(filterColumns []string, templates ...codersdk.Template) string { | ||
tableWriter := cliui.Table() | ||
header := table.Row{ | ||
"Name", "Created At", "Last Updated", "Organization ID", "Provisioner", | ||
"Active Version ID", "Used By", "Max TTL", "Min Autostart"} | ||
tableWriter.AppendHeader(header) | ||
tableWriter.SetColumnConfigs(cliui.FilterTableColumns(header, filterColumns)) | ||
tableWriter.SortBy([]table.SortBy{{ | ||
Name: "name", | ||
}}) | ||
for _, template := range templates { | ||
suffix := "" | ||
if template.WorkspaceOwnerCount != 1 { | ||
suffix = "s" | ||
} | ||
tableWriter.AppendRow(table.Row{ | ||
template.Name, | ||
template.CreatedAt.Format("January 2, 2006"), | ||
template.UpdatedAt.Format("January 2, 2006"), | ||
template.OrganizationID.String(), | ||
template.Provisioner, | ||
template.ActiveVersionID.String(), | ||
cliui.Styles.Fuschia.Render(fmt.Sprintf("%d developer%s", template.WorkspaceOwnerCount, suffix)), | ||
(time.Duration(template.MaxTTLMillis) * time.Millisecond).String(), | ||
(time.Duration(template.MinAutostartIntervalMillis) * time.Millisecond).String(), | ||
}) | ||
} | ||
return tableWriter.Render() | ||
} |
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 am using this for debugging, figured I'd throw it in a quick branch.
What this does
Adds a way to list parameter values for a scope. Really helpful for debugging the param things I am messing with. I hide the cmd by default right now, as it lists the parameter_values, not parameter_schemes.. I think the cli should somehow distinguish the two, but don't know at the moment.
No actual values are returned from the cli, just the name + meta data.
I also added more columns templates list if they specify the columns. I needed this for debugging too.
Param list (hidden by default)
Template columns