Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c33b02

Browse files
authored
chore: include all templates in cli template list (#13841)
* chore: cli template list includes all templatesShows all accessible templates from all organizations
1 parentf927204 commit8c33b02

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

‎cli/templatelist.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
)
1212

1313
func (r*RootCmd)templateList()*serpent.Command {
14-
orgContext:=NewOrganizationContext()
1514
formatter:=cliui.NewOutputFormatter(
1615
cliui.TableFormat([]templateTableRow{}, []string{"name","organization name","last updated","used by"}),
1716
cliui.JSONFormat(),
@@ -26,17 +25,13 @@ func (r *RootCmd) templateList() *serpent.Command {
2625
r.InitClient(client),
2726
),
2827
Handler:func(inv*serpent.Invocation)error {
29-
organization,err:=orgContext.Selected(inv,client)
30-
iferr!=nil {
31-
returnerr
32-
}
33-
templates,err:=client.TemplatesByOrganization(inv.Context(),organization.ID)
28+
templates,err:=client.Templates(inv.Context(), codersdk.TemplateFilter{})
3429
iferr!=nil {
3530
returnerr
3631
}
3732

3833
iflen(templates)==0 {
39-
_,_=fmt.Fprintf(inv.Stderr,"%s No templates found in %s! Create one:\n\n",Caret,color.HiWhiteString(organization.Name))
34+
_,_=fmt.Fprintf(inv.Stderr,"%s No templates found! Create one:\n\n",Caret)
4035
_,_=fmt.Fprintln(inv.Stderr,color.HiMagentaString(" $ coder templates push <directory>\n"))
4136
returnnil
4237
}
@@ -53,6 +48,5 @@ func (r *RootCmd) templateList() *serpent.Command {
5348
}
5449

5550
formatter.AttachOptions(&cmd.Options)
56-
orgContext.AttachOptions(cmd)
5751
returncmd
5852
}

‎cli/templatelist_test.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ func TestTemplateList(t *testing.T) {
8888
client:=coderdtest.New(t,&coderdtest.Options{})
8989
owner:=coderdtest.CreateFirstUser(t,client)
9090

91-
org,err:=client.Organization(context.Background(),owner.OrganizationID)
92-
require.NoError(t,err)
93-
9491
templateAdmin,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID,rbac.RoleTemplateAdmin())
9592

9693
inv,root:=clitest.New(t,"templates","list")
@@ -110,8 +107,42 @@ func TestTemplateList(t *testing.T) {
110107

111108
require.NoError(t,<-errC)
112109

113-
pty.ExpectMatch("No templates found in")
114-
pty.ExpectMatch(org.Name)
110+
pty.ExpectMatch("No templates found")
115111
pty.ExpectMatch("Create one:")
116112
})
113+
114+
t.Run("MultiOrg",func(t*testing.T) {
115+
t.Parallel()
116+
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerDaemon:true})
117+
owner:=coderdtest.CreateFirstUser(t,client)
118+
119+
// Template in the first organization
120+
firstVersion:=coderdtest.CreateTemplateVersion(t,client,owner.OrganizationID,nil)
121+
_=coderdtest.AwaitTemplateVersionJobCompleted(t,client,firstVersion.ID)
122+
_=coderdtest.CreateTemplate(t,client,owner.OrganizationID,firstVersion.ID)
123+
124+
secondOrg:=coderdtest.CreateOrganization(t,client, coderdtest.CreateOrganizationOptions{
125+
IncludeProvisionerDaemon:true,
126+
})
127+
secondVersion:=coderdtest.CreateTemplateVersion(t,client,secondOrg.ID,nil)
128+
_=coderdtest.CreateTemplate(t,client,secondOrg.ID,secondVersion.ID)
129+
130+
// Create a site wide template admin
131+
templateAdmin,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID,rbac.RoleTemplateAdmin())
132+
133+
inv,root:=clitest.New(t,"templates","list","--output=json")
134+
clitest.SetupConfig(t,templateAdmin,root)
135+
136+
ctx,cancelFunc:=context.WithTimeout(context.Background(),testutil.WaitLong)
137+
defercancelFunc()
138+
139+
out:=bytes.NewBuffer(nil)
140+
inv.Stdout=out
141+
err:=inv.WithContext(ctx).Run()
142+
require.NoError(t,err)
143+
144+
vartemplates []codersdk.Template
145+
require.NoError(t,json.Unmarshal(out.Bytes(),&templates))
146+
require.Len(t,templates,2)
147+
})
117148
}

‎cli/testdata/coder_templates_list_--help.golden

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ USAGE:
88
Aliases: ls
99

1010
OPTIONS:
11-
-O, --org string, $CODER_ORGANIZATION
12-
Select which organization (uuid or name) to use.
13-
1411
-c, --column string-array (default: name,organization name,last updated,used by)
1512
Columns to display in table output. Available columns: name, created
1613
at, last updated, organization id, organization name, provisioner,

‎docs/cli/templates_list.md

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp