feat(cli): add shell completions (#14341)

This commit is contained in:
Ethan
2024-08-20 14:47:46 +10:00
committed by GitHub
parent 6f9b3c1592
commit 0b2ba96065
80 changed files with 510 additions and 418 deletions
+6 -8
View File
@@ -32,7 +32,7 @@ func (r *RootCmd) features() *serpent.Command {
func (r *RootCmd) featuresList() *serpent.Command {
var (
featureColumns = []string{"Name", "Entitlement", "Enabled", "Limit", "Actual"}
featureColumns = []string{"name", "entitlement", "enabled", "limit", "actual"}
columns []string
outputFormat string
)
@@ -85,18 +85,16 @@ func (r *RootCmd) featuresList() *serpent.Command {
{
Flag: "column",
FlagShorthand: "c",
Description: fmt.Sprintf("Specify a column to filter in the table. Available columns are: %s.",
strings.Join(featureColumns, ", "),
),
Default: strings.Join(featureColumns, ","),
Value: serpent.StringArrayOf(&columns),
Description: "Specify columns to filter in the table.",
Default: strings.Join(featureColumns, ","),
Value: serpent.EnumArrayOf(&columns, featureColumns...),
},
{
Flag: "output",
FlagShorthand: "o",
Description: "Output format. Available formats are: table, json.",
Description: "Output format.",
Default: "table",
Value: serpent.StringOf(&outputFormat),
Value: serpent.EnumOf(&outputFormat, "table", "json"),
},
}
+3 -3
View File
@@ -69,10 +69,10 @@ type groupTableRow struct {
// For table output:
Name string `json:"-" table:"name,default_sort"`
DisplayName string `json:"-" table:"display_name"`
OrganizationID uuid.UUID `json:"-" table:"organization_id"`
DisplayName string `json:"-" table:"display name"`
OrganizationID uuid.UUID `json:"-" table:"organization id"`
Members []string `json:"-" table:"members"`
AvatarURL string `json:"-" table:"avatar_url"`
AvatarURL string `json:"-" table:"avatar url"`
}
func groupsToRows(groups ...codersdk.Group) []groupTableRow {
+2 -2
View File
@@ -140,11 +140,11 @@ func (r *RootCmd) licensesList() *serpent.Command {
type tableLicense struct {
ID int32 `table:"id,default_sort"`
UUID uuid.UUID `table:"uuid" format:"uuid"`
UploadedAt time.Time `table:"uploaded_at" format:"date-time"`
UploadedAt time.Time `table:"uploaded at" format:"date-time"`
// Features is the formatted string for the license claims.
// Used for the table view.
Features string `table:"features"`
ExpiresAt time.Time `table:"expires_at" format:"date-time"`
ExpiresAt time.Time `table:"expires at" format:"date-time"`
Trial bool `table:"trial"`
}
+1 -1
View File
@@ -111,7 +111,7 @@ func TestEnterpriseListOrganizationMembers(t *testing.T) {
OrganizationID: owner.OrganizationID,
}, rbac.ScopedRoleOrgAdmin(owner.OrganizationID))
inv, root := clitest.New(t, "organization", "members", "list", "-c", "user_id,username,organization_roles")
inv, root := clitest.New(t, "organization", "members", "list", "-c", "user id,username,organization roles")
clitest.SetupConfig(t, client, root)
buf := new(bytes.Buffer)
+4 -5
View File
@@ -6,12 +6,11 @@ USAGE:
Aliases: ls
OPTIONS:
-c, --column string-array (default: Name,Entitlement,Enabled,Limit,Actual)
Specify a column to filter in the table. Available columns are: Name,
Entitlement, Enabled, Limit, Actual.
-c, --column [name|entitlement|enabled|limit|actual] (default: name,entitlement,enabled,limit,actual)
Specify columns to filter in the table.
-o, --output string (default: table)
Output format. Available formats are: table, json.
-o, --output table|json (default: table)
Output format.
———
Run `coder --help` for a list of global options.
+4 -5
View File
@@ -9,12 +9,11 @@ OPTIONS:
-O, --org string, $CODER_ORGANIZATION
Select which organization (uuid or name) to use.
-c, --column string-array (default: name,display name,organization id,members,avatar url)
Columns to display in table output. Available columns: name, display
name, organization id, members, avatar url.
-c, --column [name|display name|organization id|members|avatar url] (default: name,display name,organization id,members,avatar url)
Columns to display in table output.
-o, --output string (default: table)
Output format. Available formats: table, json.
-o, --output table|json (default: table)
Output format.
———
Run `coder --help` for a list of global options.
+4 -5
View File
@@ -8,12 +8,11 @@ USAGE:
Aliases: ls
OPTIONS:
-c, --column string-array (default: ID,UUID,Expires At,Uploaded At,Features)
Columns to display in table output. Available columns: id, uuid,
uploaded at, features, expires at, trial.
-c, --column [id|uuid|uploaded at|features|expires at|trial] (default: ID,UUID,Expires At,Uploaded At,Features)
Columns to display in table output.
-o, --output string (default: table)
Output format. Available formats: table, json.
-o, --output table|json (default: table)
Output format.
———
Run `coder --help` for a list of global options.
+1 -1
View File
@@ -442,7 +442,7 @@ func newUpdateProxyResponseFormatter() *updateProxyResponseFormatter {
}),
cliui.JSONFormat(),
// Table formatter expects a slice, make a slice of one.
cliui.ChangeFormatterData(cliui.TableFormat([]codersdk.UpdateWorkspaceProxyResponse{}, []string{"proxy name", "proxy url", "proxy token"}),
cliui.ChangeFormatterData(cliui.TableFormat([]codersdk.UpdateWorkspaceProxyResponse{}, []string{"name", "url", "proxy token"}),
func(data any) (any, error) {
response, ok := data.(codersdk.UpdateWorkspaceProxyResponse)
if !ok {