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

Method templatePush

cli/templatepush.go:28–270  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26)
27
28func (r *RootCmd) templatePush() *serpent.Command {
29 var (
30 versionName string
31 provisioner string
32 workdir string
33 variablesFile string
34 commandLineVariables []string
35 alwaysPrompt bool
36 provisionerTags []string
37 uploadFlags templateUploadFlags
38 activate bool
39 orgContext = NewOrganizationContext()
40 )
41 cmd := &serpent.Command{
42 Use: "push [template]",
43 Short: "Create or update a template from the current directory or as specified by flag",
44 Middleware: serpent.Chain(
45 serpent.RequireRangeArgs(0, 1),
46 ),
47 Handler: func(inv *serpent.Invocation) error {
48 client, err := r.InitClient(inv)
49 if err != nil {
50 return err
51 }
52 uploadFlags.setWorkdir(workdir)
53
54 organization, err := orgContext.Selected(inv, client)
55 if err != nil {
56 return err
57 }
58
59 name, err := uploadFlags.templateName(inv)
60 if err != nil {
61 return err
62 }
63
64 err = codersdk.NameValid(name)
65 if err != nil {
66 return xerrors.Errorf("template name %q is invalid: %w", name, err)
67 }
68
69 if versionName != "" {
70 err = codersdk.TemplateVersionNameValid(versionName)
71 if err != nil {
72 return xerrors.Errorf("template version name %q is invalid: %w", versionName, err)
73 }
74 }
75
76 var createTemplate bool
77 template, err := client.TemplateByName(inv.Context(), organization.ID, name)
78 if err != nil {
79 var apiError *codersdk.Error
80 if errors.As(err, &apiError) && apiError.StatusCode() != http.StatusNotFound {
81 return err
82 }
83 // Template doesn't exist, create it.
84 createTemplate = true
85 }

Callers 1

templatesMethod · 0.95

Calls 15

InitClientMethod · 0.95
StatusCodeMethod · 0.95
NameValidFunction · 0.92
TemplateVersionNameValidFunction · 0.92
WarnFunction · 0.92
InfoFunction · 0.92
CodeFunction · 0.92
DiscoverVarsFilesFunction · 0.92
ParseUserVariableValuesFunction · 0.92
ProvisionerTypeTypeAlias · 0.92
WrapFunction · 0.92
KeywordFunction · 0.92

Tested by

no test coverage detected