Skip to content

Commit 7cd6e9c

Browse files
authored
fix: return provisioners in desc order and add limit to cli (#16720)
1 parent 7c035a4 commit 7cd6e9c

File tree

8 files changed

+36
-6
lines changed

8 files changed

+36
-6
lines changed

cli/provisioners.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (r *RootCmd) provisionerList() *serpent.Command {
3939
cliui.TableFormat([]provisionerDaemonRow{}, []string{"name", "organization", "status", "key name", "created at", "last seen at", "version", "tags"}),
4040
cliui.JSONFormat(),
4141
)
42+
limit int64
4243
)
4344

4445
cmd := &serpent.Command{
@@ -57,7 +58,9 @@ func (r *RootCmd) provisionerList() *serpent.Command {
5758
return xerrors.Errorf("current organization: %w", err)
5859
}
5960

60-
daemons, err := client.OrganizationProvisionerDaemons(ctx, org.ID, nil)
61+
daemons, err := client.OrganizationProvisionerDaemons(ctx, org.ID, &codersdk.OrganizationProvisionerDaemonsOptions{
62+
Limit: int(limit),
63+
})
6164
if err != nil {
6265
return xerrors.Errorf("list provisioner daemons: %w", err)
6366
}
@@ -86,6 +89,17 @@ func (r *RootCmd) provisionerList() *serpent.Command {
8689
},
8790
}
8891

92+
cmd.Options = append(cmd.Options, []serpent.Option{
93+
{
94+
Flag: "limit",
95+
FlagShorthand: "l",
96+
Env: "CODER_PROVISIONER_LIST_LIMIT",
97+
Description: "Limit the number of provisioners returned.",
98+
Default: "50",
99+
Value: serpent.Int64Of(&limit),
100+
},
101+
}...)
102+
89103
orgContext.AttachOptions(cmd)
90104
formatter.AttachOptions(&cmd.Options)
91105

cli/testdata/coder_provisioner_list_--help.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ OPTIONS:
1414
-c, --column [id|organization id|created at|last seen at|name|version|api version|tags|key name|status|current job id|current job status|current job template name|current job template icon|current job template display name|previous job id|previous job status|previous job template name|previous job template icon|previous job template display name|organization] (default: name,organization,status,key name,created at,last seen at,version,tags)
1515
Columns to display in table output.
1616

17+
-l, --limit int, $CODER_PROVISIONER_LIST_LIMIT (default: 50)
18+
Limit the number of provisioners returned.
19+
1720
-o, --output table|json (default: table)
1821
Output format.
1922

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4073,7 +4073,7 @@ func (q *FakeQuerier) GetProvisionerDaemonsWithStatusByOrganization(ctx context.
40734073
}
40744074

40754075
slices.SortFunc(rows, func(a, b database.GetProvisionerDaemonsWithStatusByOrganizationRow) int {
4076-
return a.ProvisionerDaemon.CreatedAt.Compare(b.ProvisionerDaemon.CreatedAt)
4076+
return b.ProvisionerDaemon.CreatedAt.Compare(a.ProvisionerDaemon.CreatedAt)
40774077
})
40784078

40794079
if arg.Limit.Valid && arg.Limit.Int32 > 0 && len(rows) > int(arg.Limit.Int32) {

coderd/database/queries.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/provisionerdaemons.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ WHERE
111111
AND (COALESCE(array_length(@ids::uuid[], 1), 0) = 0 OR pd.id = ANY(@ids::uuid[]))
112112
AND (@tags::tagset = 'null'::tagset OR provisioner_tagset_contains(pd.tags::tagset, @tags::tagset))
113113
ORDER BY
114-
pd.created_at ASC
114+
pd.created_at DESC
115115
LIMIT
116116
sqlc.narg('limit')::int;
117117

coderd/provisionerdaemons_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ func TestProvisionerDaemons(t *testing.T) {
159159
})
160160
require.NoError(t, err)
161161
require.Len(t, daemons, 2)
162-
require.Equal(t, pd1.ID, daemons[0].ID)
163-
require.Equal(t, pd2.ID, daemons[1].ID)
162+
require.Equal(t, pd1.ID, daemons[1].ID)
163+
require.Equal(t, pd2.ID, daemons[0].ID)
164164
})
165165

166166
t.Run("Tags", func(t *testing.T) {

docs/reference/cli/provisioner_list.md

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

enterprise/cli/testdata/coder_provisioner_list_--help.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ OPTIONS:
1414
-c, --column [id|organization id|created at|last seen at|name|version|api version|tags|key name|status|current job id|current job status|current job template name|current job template icon|current job template display name|previous job id|previous job status|previous job template name|previous job template icon|previous job template display name|organization] (default: name,organization,status,key name,created at,last seen at,version,tags)
1515
Columns to display in table output.
1616

17+
-l, --limit int, $CODER_PROVISIONER_LIST_LIMIT (default: 50)
18+
Limit the number of provisioners returned.
19+
1720
-o, --output table|json (default: table)
1821
Output format.
1922

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy