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

Method templateCreate

cli/templatecreate.go:18–251  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16)
17
18func (r *RootCmd) templateCreate() *serpent.Command {
19 var (
20 provisioner string
21 provisionerTags []string
22 variablesFile string
23 commandLineVariables []string
24 disableEveryone bool
25 requireActiveVersion bool
26
27 defaultTTL time.Duration
28 failureTTL time.Duration
29 dormancyThreshold time.Duration
30 dormancyAutoDeletion time.Duration
31
32 uploadFlags templateUploadFlags
33 orgContext = NewOrganizationContext()
34 )
35 cmd := &serpent.Command{
36 Use: "create [name]",
37 Short: "DEPRECATED: Create a template from the current directory or as specified by flag",
38 Middleware: serpent.Chain(
39 serpent.RequireRangeArgs(0, 1),
40 cliui.DeprecationWarning(
41 "Use `coder templates push` command for creating and updating templates. \n"+
42 "Use `coder templates edit` command for editing template settings. ",
43 ),
44 ),
45 Handler: func(inv *serpent.Invocation) error {
46 client, err := r.InitClient(inv)
47 if err != nil {
48 return err
49 }
50 isTemplateSchedulingOptionsSet := failureTTL != 0 || dormancyThreshold != 0 || dormancyAutoDeletion != 0
51
52 if isTemplateSchedulingOptionsSet || requireActiveVersion {
53 entitlements, err := client.Entitlements(inv.Context())
54 if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusNotFound {
55 return xerrors.Errorf("your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags")
56 } else if err != nil {
57 return xerrors.Errorf("get entitlements: %w", err)
58 }
59
60 if isTemplateSchedulingOptionsSet {
61 if !entitlements.Features[codersdk.FeatureAdvancedTemplateScheduling].Enabled {
62 return xerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl, or --inactivity-ttl")
63 }
64 }
65
66 if requireActiveVersion {
67 if !entitlements.Features[codersdk.FeatureAccessControl].Enabled {
68 return xerrors.Errorf("your license is not entitled to use enterprise access control, so you cannot set --require-active-version")
69 }
70 }
71 }
72
73 organization, err := orgContext.Selected(inv, client)
74 if err != nil {
75 return err

Callers 1

templatesMethod · 0.95

Calls 15

InitClientMethod · 0.95
DeprecationWarningFunction · 0.92
AsErrorFunction · 0.92
DiscoverVarsFilesFunction · 0.92
ParseUserVariableValuesFunction · 0.92
ProvisionerTypeTypeAlias · 0.92
PromptFunction · 0.92
RefFunction · 0.92
SkipPromptOptionFunction · 0.92
NewOrganizationContextFunction · 0.85
ParseProvisionerTagsFunction · 0.85

Tested by

no test coverage detected