Skip to content

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

Merged
merged 6 commits into from
Jun 15, 2022

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Jun 15, 2022

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)

$ coder parameters list workspace my-workspace
NAME          SOURCE SCHEME  DESTINATION SCHEME    
docker_image  data           provisioner_variable 

Template columns

$ ./coder templates list -c name -c active_version_id                                                                                                                                                                                              
NAME    ACTIVE VERSION ID                     
docker  8898efde-8f95-4cdd-8ea8-fee121510361 

@Emyrk Emyrk requested a review from a team as a code owner June 15, 2022 16:39
@Emyrk Emyrk requested a review from johnstcn June 15, 2022 18:05
Copy link
Member

@Kira-Pilot Kira-Pilot left a 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.

Copy link
Member

@johnstcn johnstcn left a 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!

Comment on lines 6 to 9
"github.com/google/uuid"
"golang.org/x/xerrors"

"github.com/spf13/cobra"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: imports

Comment on lines +33 to +54
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()
}
Copy link
Member

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.

Comment on lines +49 to +77
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()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Emyrk Emyrk merged commit 75205f5 into main Jun 15, 2022
@Emyrk Emyrk deleted the stevenmasley/param_list branch June 15, 2022 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants