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

Commit3f04e98

Browse files
authored
feat(cli): pull templates in zip format (#12032)
1 parent213ae69 commit3f04e98

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

‎cli/templatepull.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
func (r*RootCmd)templatePull()*clibase.Cmd {
1818
var (
1919
tarModebool
20+
zipModebool
2021
versionNamestring
2122
)
2223

@@ -39,6 +40,10 @@ func (r *RootCmd) templatePull() *clibase.Cmd {
3940
dest=inv.Args[1]
4041
}
4142

43+
iftarMode&&zipMode {
44+
returnxerrors.Errorf("either tar or zip can be selected")
45+
}
46+
4247
organization,err:=CurrentOrganization(inv,client)
4348
iferr!=nil {
4449
returnxerrors.Errorf("get current organization: %w",err)
@@ -98,17 +103,25 @@ func (r *RootCmd) templatePull() *clibase.Cmd {
98103

99104
cliui.Info(inv.Stderr,"Pulling template version "+cliui.Bold(templateVersion.Name)+"...")
100105

106+
varfileFormatstring// empty = default, so .tar
107+
ifzipMode {
108+
fileFormat=codersdk.FormatZip
109+
}
110+
101111
// Download the tar archive.
102-
raw,ctype,err:=client.Download(ctx,templateVersion.Job.FileID)
112+
raw,ctype,err:=client.DownloadWithFormat(ctx,templateVersion.Job.FileID,fileFormat)
103113
iferr!=nil {
104114
returnxerrors.Errorf("download template: %w",err)
105115
}
106116

107-
ifctype!=codersdk.ContentTypeTar {
117+
iffileFormat==""&&ctype!=codersdk.ContentTypeTar {
108118
returnxerrors.Errorf("unexpected Content-Type %q, expecting %q",ctype,codersdk.ContentTypeTar)
109119
}
120+
iffileFormat==codersdk.FormatZip&&ctype!=codersdk.ContentTypeZip {
121+
returnxerrors.Errorf("unexpected Content-Type %q, expecting %q",ctype,codersdk.ContentTypeZip)
122+
}
110123

111-
iftarMode {
124+
iftarMode||zipMode{
112125
_,err=inv.Stdout.Write(raw)
113126
returnerr
114127
}
@@ -152,6 +165,12 @@ func (r *RootCmd) templatePull() *clibase.Cmd {
152165

153166
Value:clibase.BoolOf(&tarMode),
154167
},
168+
{
169+
Description:"Output the template as a zip archive to stdout.",
170+
Flag:"zip",
171+
172+
Value:clibase.BoolOf(&zipMode),
173+
},
155174
{
156175
Description:"The name of the template version to pull. Use 'active' to pull the active version, 'latest' to pull the latest version, or the name of the template version to pull.",
157176
Flag:"version",

‎cli/templatepull_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli_test
22

33
import (
4+
"archive/tar"
45
"bytes"
56
"context"
67
"crypto/sha256"
@@ -15,6 +16,7 @@ import (
1516
"github.com/stretchr/testify/require"
1617

1718
"github.com/coder/coder/v2/cli/clitest"
19+
"github.com/coder/coder/v2/coderd"
1820
"github.com/coder/coder/v2/coderd/coderdtest"
1921
"github.com/coder/coder/v2/coderd/rbac"
2022
"github.com/coder/coder/v2/provisioner/echo"
@@ -81,6 +83,7 @@ func TestTemplatePull_Stdout(t *testing.T) {
8183
_=coderdtest.AwaitTemplateVersionJobCompleted(t,client,updatedVersion.ID)
8284
coderdtest.UpdateActiveTemplateVersion(t,client,template.ID,updatedVersion.ID)
8385

86+
// Verify .tar format
8487
inv,root:=clitest.New(t,"templates","pull","--tar",template.Name)
8588
clitest.SetupConfig(t,templateAdmin,root)
8689

@@ -89,8 +92,21 @@ func TestTemplatePull_Stdout(t *testing.T) {
8992

9093
err=inv.Run()
9194
require.NoError(t,err)
92-
9395
require.True(t,bytes.Equal(expected,buf.Bytes()),"tar files differ")
96+
97+
// Verify .zip format
98+
tarReader:=tar.NewReader(bytes.NewReader(expected))
99+
expectedZip,err:=coderd.CreateZipFromTar(tarReader)
100+
require.NoError(t,err)
101+
102+
inv,root=clitest.New(t,"templates","pull","--zip",template.Name)
103+
clitest.SetupConfig(t,templateAdmin,root)
104+
buf.Reset()
105+
inv.Stdout=&buf
106+
107+
err=inv.Run()
108+
require.NoError(t,err)
109+
require.True(t,bytes.Equal(expectedZip,buf.Bytes()),"zip files differ")
94110
}
95111

96112
// Stdout tests that 'templates pull' pulls down the non-latest active template

‎cli/testdata/coder_templates_pull_--help.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ OPTIONS:
1717
-y, --yes bool
1818
Bypass prompts.
1919

20+
--zip bool
21+
Output the template as a zip archive to stdout.
22+
2023
———
2124
Run `coder --help` for a list of global options.

‎docs/cli/templates_pull.md

Lines changed: 8 additions & 0 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