MCPcopy Index your code
hub / github.com/coder/coder / templatePull

Method templatePull

cli/templatepull.go:18–196  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16)
17
18func (r *RootCmd) templatePull() *serpent.Command {
19 var (
20 tarMode bool
21 zipMode bool
22 versionName string
23 orgContext = NewOrganizationContext()
24 )
25
26 cmd := &serpent.Command{
27 Use: "pull <name> [destination]",
28 Short: "Download the active, latest, or specified version of a template to a path.",
29 Middleware: serpent.Chain(
30 serpent.RequireRangeArgs(1, 2),
31 ),
32 Handler: func(inv *serpent.Invocation) error {
33 var (
34 ctx = inv.Context()
35 templateName = inv.Args[0]
36 dest string
37 )
38 client, err := r.InitClient(inv)
39 if err != nil {
40 return err
41 }
42
43 if len(inv.Args) > 1 {
44 dest = inv.Args[1]
45 }
46
47 if tarMode && zipMode {
48 return xerrors.Errorf("either tar or zip can be selected")
49 }
50
51 organization, err := orgContext.Selected(inv, client)
52 if err != nil {
53 return xerrors.Errorf("get current organization: %w", err)
54 }
55
56 template, err := client.TemplateByName(ctx, organization.ID, templateName)
57 if err != nil {
58 return xerrors.Errorf("get template by name: %w", err)
59 }
60
61 var latestVersion codersdk.TemplateVersion
62 {
63 // Determine the latest template version and compare with the
64 // active version. If they aren't the same, warn the user.
65 versions, err := client.TemplateVersionsByTemplate(ctx, codersdk.TemplateVersionsByTemplateRequest{
66 TemplateID: template.ID,
67 })
68 if err != nil {
69 return xerrors.Errorf("template versions by template: %w", err)
70 }
71
72 if len(versions) == 0 {
73 return xerrors.Errorf("no template versions for template %q", templateName)
74 }
75

Callers 1

templatesMethod · 0.95

Calls 15

InitClientMethod · 0.95
WarnFunction · 0.92
CodeFunction · 0.92
InfoFunction · 0.92
BoldFunction · 0.92
PromptFunction · 0.92
UntarFunction · 0.92
SkipPromptOptionFunction · 0.92
NewOrganizationContextFunction · 0.85
SelectedMethod · 0.80
TemplateVersionByNameMethod · 0.80

Tested by

no test coverage detected