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

Method templateEdit

cli/templateedit.go:17–320  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func (r *RootCmd) templateEdit() *serpent.Command {
18 const deprecatedFlagName = "deprecated"
19 var (
20 name string
21 displayName string
22 description string
23 icon string
24 defaultTTL time.Duration
25 activityBump time.Duration
26 autostopRequirementDaysOfWeek []string
27 autostopRequirementWeeks int64
28 autostartRequirementDaysOfWeek []string
29 failureTTL time.Duration
30 dormancyThreshold time.Duration
31 dormancyAutoDeletion time.Duration
32 allowUserCancelWorkspaceJobs bool
33 allowUserAutostart bool
34 allowUserAutostop bool
35 requireActiveVersion bool
36 deprecationMessage string
37 disableEveryone bool
38 orgContext = NewOrganizationContext()
39 )
40
41 cmd := &serpent.Command{
42 Use: "edit <template>",
43 Middleware: serpent.Chain(
44 serpent.RequireNArgs(1),
45 ),
46 Short: "Edit the metadata of a template by name.",
47 Handler: func(inv *serpent.Invocation) error {
48 client, err := r.InitClient(inv)
49 if err != nil {
50 return err
51 }
52 unsetAutostopRequirementDaysOfWeek := len(autostopRequirementDaysOfWeek) == 1 && autostopRequirementDaysOfWeek[0] == "none"
53 requiresScheduling := (len(autostopRequirementDaysOfWeek) > 0 && !unsetAutostopRequirementDaysOfWeek) ||
54 autostopRequirementWeeks > 0 ||
55 !allowUserAutostart ||
56 !allowUserAutostop ||
57 failureTTL != 0 ||
58 dormancyThreshold != 0 ||
59 dormancyAutoDeletion != 0 ||
60 len(autostartRequirementDaysOfWeek) > 0
61
62 requiresEntitlement := requiresScheduling || requireActiveVersion
63 if requiresEntitlement {
64 entitlements, err := client.Entitlements(inv.Context())
65 if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusNotFound {
66 return xerrors.Errorf("your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags")
67 } else if err != nil {
68 return xerrors.Errorf("get entitlements: %w", err)
69 }
70
71 if requiresScheduling && !entitlements.Features[codersdk.FeatureAdvancedTemplateScheduling].Enabled {
72 return xerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl, --inactivityTTL, --allow-user-autostart=false or --allow-user-autostop=false")
73 }
74

Callers 1

templatesMethod · 0.95

Calls 15

InitClientMethod · 0.95
AsErrorFunction · 0.92
RefFunction · 0.92
SkipPromptOptionFunction · 0.92
NewOrganizationContextFunction · 0.85
userSetOptionFunction · 0.85
EntitlementsMethod · 0.80
SelectedMethod · 0.80
DurationMethod · 0.80
UpdateTemplateMetaMethod · 0.80
ContextMethod · 0.65
TemplateByNameMethod · 0.65

Tested by

no test coverage detected