@@ -11,6 +11,7 @@ import (
11
11
"os"
12
12
13
13
"cdr.dev/coder-cli/coder-sdk"
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"
@@ -160,6 +161,7 @@ func createEnvCmd() *cobra.Command {
160
161
tag string
161
162
follow bool
162
163
useCVM bool
164
+ useAS bool
163
165
)
164
166
165
167
cmd := & cobra.Command {
@@ -170,6 +172,9 @@ func createEnvCmd() *cobra.Command {
170
172
Example : `# create a new environment using default resource amounts
171
173
coder envs create my-new-env --image ubuntu
172
174
coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ubuntu` ,
175
+ PreRun : func (cmd * cobra.Command , args []string ) {
176
+ autoStartInfo ()
177
+ },
173
178
RunE : func (cmd * cobra.Command , args []string ) error {
174
179
ctx := cmd .Context ()
175
180
if img == "" {
@@ -200,15 +205,16 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
200
205
201
206
// ExactArgs(1) ensures our name value can't panic on an out of bounds.
202
207
createReq := & coder.CreateEnvironmentRequest {
203
- Name : args [0 ],
204
- ImageID : importedImg .ID ,
205
- OrgID : importedImg .OrganizationID ,
206
- ImageTag : tag ,
207
- CPUCores : cpu ,
208
- MemoryGB : memory ,
209
- DiskGB : disk ,
210
- GPUs : gpus ,
211
- UseContainerVM : useCVM ,
208
+ Name : args [0 ],
209
+ ImageID : importedImg .ID ,
210
+ OrgID : importedImg .OrganizationID ,
211
+ ImageTag : tag ,
212
+ CPUCores : cpu ,
213
+ MemoryGB : memory ,
214
+ DiskGB : disk ,
215
+ GPUs : gpus ,
216
+ UseContainerVM : useCVM ,
217
+ EnableAutoStart : useAS ,
212
218
}
213
219
214
220
// if any of these defaulted to their zero value we provision
@@ -252,6 +258,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
252
258
cmd .Flags ().StringVarP (& img , "image" , "i" , "" , "name of the image to base the environment off of." )
253
259
cmd .Flags ().BoolVar (& follow , "follow" , false , "follow buildlog after initiating rebuild" )
254
260
cmd .Flags ().BoolVar (& useCVM , "container-based-vm" , false , "deploy the environment as a Container-based VM" )
261
+ cmd .Flags ().BoolVar (& useAS , "enable-autostart" , false , "automatically start this environment at your preferred time." )
255
262
_ = cmd .MarkFlagRequired ("image" )
256
263
return cmd
257
264
}
@@ -384,6 +391,9 @@ func editEnvCmd() *cobra.Command {
384
391
Example : `coder envs edit back-end-env --cpu 4
385
392
386
393
coder envs edit back-end-env --disk 20` ,
394
+ PreRun : func (cmd * cobra.Command , args []string ) {
395
+ autoStartInfo ()
396
+ },
387
397
RunE : func (cmd * cobra.Command , args []string ) error {
388
398
ctx := cmd .Context ()
389
399
client , err := newClient (ctx )
@@ -611,3 +621,17 @@ func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf)
611
621
}
612
622
return & updateReq , nil
613
623
}
624
+
625
+ func autoStartInfo () {
626
+ var preferencesURI string
627
+
628
+ accessURI , err := config .URL .Read ()
629
+ if err != nil {
630
+ // Error is fairly benign in this case, fallback to relative URI
631
+ preferencesURI = "/preferences"
632
+ } else {
633
+ preferencesURI = fmt .Sprintf ("%s%s" , accessURI , "/preferences?tab=autostart" )
634
+ }
635
+
636
+ clog .LogInfo ("⚡NEW: Automate daily environment startup" , "Visit " + preferencesURI + " to configure your preferred time" )
637
+ }
0 commit comments