@@ -11,6 +11,7 @@ import (
11
11
12
12
"cdr.dev/coder-cli/coder-sdk"
13
13
"cdr.dev/coder-cli/internal/coderutil"
14
+ "cdr.dev/coder-cli/internal/config"
14
15
"cdr.dev/coder-cli/internal/x/xcobra"
15
16
"cdr.dev/coder-cli/pkg/clog"
16
17
"cdr.dev/coder-cli/pkg/tablewriter"
151
152
152
153
func createEnvCmd () * cobra.Command {
153
154
var (
154
- org string
155
- cpu float32
156
- memory float32
157
- disk int
158
- gpus int
159
- img string
160
- tag string
161
- follow bool
162
- useCVM bool
163
- providerName string
155
+ org string
156
+ cpu float32
157
+ memory float32
158
+ disk int
159
+ gpus int
160
+ img string
161
+ tag string
162
+ follow bool
163
+ useCVM bool
164
+ providerName string
165
+ enableAutostart bool
164
166
)
165
167
166
168
cmd := & cobra.Command {
@@ -171,6 +173,9 @@ func createEnvCmd() *cobra.Command {
171
173
Example : `# create a new environment using default resource amounts
172
174
coder envs create my-new-env --image ubuntu
173
175
coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ubuntu` ,
176
+ PreRun : func (cmd * cobra.Command , args []string ) {
177
+ autoStartInfo ()
178
+ },
174
179
RunE : func (cmd * cobra.Command , args []string ) error {
175
180
ctx := cmd .Context ()
176
181
if img == "" {
@@ -214,17 +219,18 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
214
219
215
220
// ExactArgs(1) ensures our name value can't panic on an out of bounds.
216
221
createReq := & coder.CreateEnvironmentRequest {
217
- Name : args [0 ],
218
- ImageID : importedImg .ID ,
219
- OrgID : importedImg .OrganizationID ,
220
- ImageTag : tag ,
221
- CPUCores : cpu ,
222
- MemoryGB : memory ,
223
- DiskGB : disk ,
224
- GPUs : gpus ,
225
- UseContainerVM : useCVM ,
226
- ResourcePoolID : provider .ID ,
227
- Namespace : provider .DefaultNamespace ,
222
+ Name : args [0 ],
223
+ ImageID : importedImg .ID ,
224
+ OrgID : importedImg .OrganizationID ,
225
+ ImageTag : tag ,
226
+ CPUCores : cpu ,
227
+ MemoryGB : memory ,
228
+ DiskGB : disk ,
229
+ GPUs : gpus ,
230
+ UseContainerVM : useCVM ,
231
+ ResourcePoolID : provider .ID ,
232
+ Namespace : provider .DefaultNamespace ,
233
+ EnableAutoStart : enableAutostart ,
228
234
}
229
235
230
236
// if any of these defaulted to their zero value we provision
@@ -269,6 +275,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
269
275
cmd .Flags ().StringVar (& providerName , "provider" , "" , "name of Workspace Provider with which to create the environment" )
270
276
cmd .Flags ().BoolVar (& follow , "follow" , false , "follow buildlog after initiating rebuild" )
271
277
cmd .Flags ().BoolVar (& useCVM , "container-based-vm" , false , "deploy the environment as a Container-based VM" )
278
+ cmd .Flags ().BoolVar (& enableAutostart , "enable-autostart" , false , "automatically start this environment at your preferred time." )
272
279
_ = cmd .MarkFlagRequired ("image" )
273
280
return cmd
274
281
}
@@ -417,6 +424,9 @@ func editEnvCmd() *cobra.Command {
417
424
Example : `coder envs edit back-end-env --cpu 4
418
425
419
426
coder envs edit back-end-env --disk 20` ,
427
+ PreRun : func (cmd * cobra.Command , args []string ) {
428
+ autoStartInfo ()
429
+ },
420
430
RunE : func (cmd * cobra.Command , args []string ) error {
421
431
ctx := cmd .Context ()
422
432
client , err := newClient (ctx )
@@ -644,3 +654,18 @@ func buildUpdateReq(ctx context.Context, client coder.Client, conf updateConf) (
644
654
}
645
655
return & updateReq , nil
646
656
}
657
+
658
+ // TODO (Grey): Remove education in a future non-patch release.
659
+ func autoStartInfo () {
660
+ var preferencesURI string
661
+
662
+ accessURI , err := config .URL .Read ()
663
+ if err != nil {
664
+ // Error is fairly benign in this case, fallback to relative URI
665
+ preferencesURI = "/preferences"
666
+ } else {
667
+ preferencesURI = fmt .Sprintf ("%s%s" , accessURI , "/preferences?tab=autostart" )
668
+ }
669
+
670
+ clog .LogInfo ("⚡NEW: Automate daily environment startup" , "Visit " + preferencesURI + " to configure your preferred time" )
671
+ }
0 commit comments