@@ -141,6 +141,10 @@ coder envs --user charlie@coder.com ls -o json \
141
141
func createEnvCmd (user * string ) * cobra.Command {
142
142
var (
143
143
org string
144
+ cpu float32
145
+ memory float32
146
+ disk int
147
+ gpus int
144
148
img string
145
149
tag string
146
150
follow bool
@@ -150,14 +154,10 @@ func createEnvCmd(user *string) *cobra.Command {
150
154
Use : "create [environment_name]" ,
151
155
Short : "create a new environment." ,
152
156
Args : cobra .ExactArgs (1 ),
153
- // Don't unhide this command until we can pass image names instead of image id's.
154
- Hidden : true ,
155
- Long : "Create a new environment under the active user." ,
157
+ Long : "Create a new Coder environment." ,
156
158
Example : `# create a new environment using default resource amounts
157
- coder envs create --image 5f443b16-30652892427b955601330fa5 my-env-name
158
-
159
- # create a new environment using custom resource amounts
160
- coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955601330fa5 my-env-name` ,
159
+ coder envs create my-new-env --image ubuntu
160
+ coder envs create my-new-powerfull-env --cpu 12 --disk 100 --memory 16 --image ubuntu` ,
161
161
RunE : func (cmd * cobra.Command , args []string ) error {
162
162
ctx := cmd .Context ()
163
163
if img == "" {
@@ -178,14 +178,11 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
178
178
return xerrors .New ("org is required for multi-org members" )
179
179
}
180
180
181
- importedImg , err := findImg (ctx ,
182
- findImgConf {
183
- client : client ,
184
- email : * user ,
185
- imgName : img ,
186
- orgName : org ,
187
- },
188
- )
181
+ importedImg , err := findImg (ctx , client , findImgConf {
182
+ email : * user ,
183
+ imgName : img ,
184
+ orgName : org ,
185
+ })
189
186
if err != nil {
190
187
return err
191
188
}
@@ -195,13 +192,11 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
195
192
Name : args [0 ],
196
193
ImageID : importedImg .ID ,
197
194
ImageTag : tag ,
195
+ CPUCores : cpu ,
196
+ MemoryGB : memory ,
197
+ DiskGB : disk ,
198
+ GPUs : gpus ,
198
199
}
199
- // We're explicitly ignoring errors for these because all we
200
- // need to now is if the numeric type is 0 or not.
201
- createReq .CPUCores , _ = cmd .Flags ().GetFloat32 ("cpu" )
202
- createReq .MemoryGB , _ = cmd .Flags ().GetFloat32 ("memory" )
203
- createReq .DiskGB , _ = cmd .Flags ().GetInt ("disk" )
204
- createReq .GPUs , _ = cmd .Flags ().GetInt ("gpus" )
205
200
206
201
// if any of these defaulted to their zero value we provision
207
202
// the create request with the imported image defaults instead.
@@ -230,17 +225,17 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
230
225
231
226
clog .LogSuccess ("creating environment..." ,
232
227
clog .BlankLine ,
233
- clog .Tipf (`run "coder envs watch-build %q " to trail the build logs` , env .Name ),
228
+ clog .Tipf (`run "coder envs watch-build %s " to trail the build logs` , env .Name ),
234
229
)
235
230
return nil
236
231
},
237
232
}
238
233
cmd .Flags ().StringVarP (& org , "org" , "o" , "" , "ID of the organization the environment should be created under." )
239
234
cmd .Flags ().StringVarP (& tag , "tag" , "t" , defaultImgTag , "tag of the image the environment will be based off of." )
240
- cmd .Flags ().Float32P ( "cpu" , "c" , 0 , "number of cpu cores the environment should be provisioned with." )
241
- cmd .Flags ().Float32P ( "memory" , "m" , 0 , "GB of RAM an environment should be provisioned with." )
242
- cmd .Flags ().IntP ( "disk" , "d" , 0 , "GB of disk storage an environment should be provisioned with." )
243
- cmd .Flags ().IntP ( "gpus" , "g" , 0 , "number GPUs an environment should be provisioned with." )
235
+ cmd .Flags ().Float32VarP ( & cpu , "cpu" , "c" , 0 , "number of cpu cores the environment should be provisioned with." )
236
+ cmd .Flags ().Float32VarP ( & memory , "memory" , "m" , 0 , "GB of RAM an environment should be provisioned with." )
237
+ cmd .Flags ().IntVarP ( & disk , "disk" , "d" , 0 , "GB of disk storage an environment should be provisioned with." )
238
+ cmd .Flags ().IntVarP ( & gpus , "gpus" , "g" , 0 , "number GPUs an environment should be provisioned with." )
244
239
cmd .Flags ().StringVarP (& img , "image" , "i" , "" , "name of the image to base the environment off of." )
245
240
cmd .Flags ().BoolVar (& follow , "follow" , false , "follow buildlog after initiating rebuild" )
246
241
_ = cmd .MarkFlagRequired ("image" )
@@ -249,22 +244,21 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
249
244
250
245
func editEnvCmd (user * string ) * cobra.Command {
251
246
var (
252
- org string
253
- img string
254
- tag string
255
- cpuCores float32
256
- memGB float32
257
- diskGB int
258
- gpus int
259
- follow bool
247
+ org string
248
+ img string
249
+ tag string
250
+ cpu float32
251
+ memory float32
252
+ disk int
253
+ gpus int
254
+ follow bool
260
255
)
261
256
262
257
cmd := & cobra.Command {
263
- Use : "edit" ,
264
- Short : "edit an existing environment owned by the active user." ,
265
- Args : cobra .ExactArgs (1 ),
266
- Hidden : true ,
267
- Long : "Edit an existing environment owned by the active user." ,
258
+ Use : "edit" ,
259
+ Short : "edit an existing environment and initiate a rebuild." ,
260
+ Args : cobra .ExactArgs (1 ),
261
+ Long : "Edit an existing environment and initate a rebuild." ,
268
262
Example : `coder envs edit back-end-env --cpu 4
269
263
270
264
coder envs edit back-end-env --disk 20` ,
@@ -292,25 +286,17 @@ coder envs edit back-end-env --disk 20`,
292
286
return xerrors .New ("org is required for multi-org members" )
293
287
}
294
288
295
- cpuCores , _ = cmd .Flags ().GetFloat32 ("cpu" )
296
- memGB , _ = cmd .Flags ().GetFloat32 ("memory" )
297
- diskGB , _ = cmd .Flags ().GetInt ("disk" )
298
- gpus , _ = cmd .Flags ().GetInt ("gpus" )
299
-
300
- req , err := buildUpdateReq (ctx ,
301
- updateConf {
302
- cpu : cpuCores ,
303
- memGB : memGB ,
304
- diskGB : diskGB ,
305
- gpus : gpus ,
306
- client : client ,
307
- environment : env ,
308
- user : user ,
309
- image : img ,
310
- imageTag : tag ,
311
- orgName : org ,
312
- },
313
- )
289
+ req , err := buildUpdateReq (ctx , client , updateConf {
290
+ cpu : cpu ,
291
+ memGB : memory ,
292
+ diskGB : disk ,
293
+ gpus : gpus ,
294
+ environment : env ,
295
+ user : user ,
296
+ image : img ,
297
+ imageTag : tag ,
298
+ orgName : org ,
299
+ })
314
300
if err != nil {
315
301
return err
316
302
}
@@ -329,18 +315,18 @@ coder envs edit back-end-env --disk 20`,
329
315
330
316
clog .LogSuccess ("applied changes to the environment, rebuilding..." ,
331
317
clog .BlankLine ,
332
- clog .Tipf (`run "coder envs watch-build %q " to trail the build logs` , envName ),
318
+ clog .Tipf (`run "coder envs watch-build %s " to trail the build logs` , envName ),
333
319
)
334
320
return nil
335
321
},
336
322
}
337
323
cmd .Flags ().StringVarP (& org , "org" , "o" , "" , "name of the organization the environment should be created under." )
338
324
cmd .Flags ().StringVarP (& img , "image" , "i" , "" , "name of the image you want the environment to be based off of." )
339
325
cmd .Flags ().StringVarP (& tag , "tag" , "t" , "latest" , "image tag of the image you want to base the environment off of." )
340
- cmd .Flags ().Float32P ( "cpu" , "c" , cpuCores , "The number of cpu cores the environment should be provisioned with." )
341
- cmd .Flags ().Float32P ( "memory" , "m" , memGB , "The amount of RAM an environment should be provisioned with." )
342
- cmd .Flags ().IntP ( "disk" , "d" , diskGB , "The amount of disk storage an environment should be provisioned with." )
343
- cmd .Flags ().IntP ( "gpu" , "g" , gpus , "The amount of disk storage to provision the environment with." )
326
+ cmd .Flags ().Float32VarP ( & cpu , "cpu" , "c" , 0 , "The number of cpu cores the environment should be provisioned with." )
327
+ cmd .Flags ().Float32VarP ( & memory , "memory" , "m" , 0 , "The amount of RAM an environment should be provisioned with." )
328
+ cmd .Flags ().IntVarP ( & disk , "disk" , "d" , 0 , "The amount of disk storage an environment should be provisioned with." )
329
+ cmd .Flags ().IntVarP ( & gpus , "gpu" , "g" , 0 , "The amount of disk storage to provision the environment with." )
344
330
cmd .Flags ().BoolVar (& follow , "follow" , false , "follow buildlog after initiating rebuild" )
345
331
return cmd
346
332
}
@@ -364,7 +350,7 @@ func rmEnvsCmd(user *string) *cobra.Command {
364
350
}
365
351
if _ , err := confirm .Run (); err != nil {
366
352
return clog .Fatal (
367
- "failed to confirm prompt " , clog .BlankLine ,
353
+ "failed to confirm deletion " , clog .BlankLine ,
368
354
clog .Tipf (`use "--force" to rebuild without a confirmation prompt` ),
369
355
)
370
356
}
@@ -400,15 +386,14 @@ type updateConf struct {
400
386
memGB float32
401
387
diskGB int
402
388
gpus int
403
- client * coder.Client
404
389
environment * coder.Environment
405
390
user * string
406
391
image string
407
392
imageTag string
408
393
orgName string
409
394
}
410
395
411
- func buildUpdateReq (ctx context.Context , conf updateConf ) (* coder.UpdateEnvironmentReq , error ) {
396
+ func buildUpdateReq (ctx context.Context , client * coder. Client , conf updateConf ) (* coder.UpdateEnvironmentReq , error ) {
412
397
var (
413
398
updateReq coder.UpdateEnvironmentReq
414
399
defaultCPUCores float32
@@ -418,14 +403,11 @@ func buildUpdateReq(ctx context.Context, conf updateConf) (*coder.UpdateEnvironm
418
403
419
404
// If this is not empty it means the user is requesting to change the environment image.
420
405
if conf .image != "" {
421
- importedImg , err := findImg (ctx ,
422
- findImgConf {
423
- client : conf .client ,
424
- email : * conf .user ,
425
- imgName : conf .image ,
426
- orgName : conf .orgName ,
427
- },
428
- )
406
+ importedImg , err := findImg (ctx , client , findImgConf {
407
+ email : * conf .user ,
408
+ imgName : conf .image ,
409
+ orgName : conf .orgName ,
410
+ })
429
411
if err != nil {
430
412
return nil , err
431
413
}
0 commit comments