@@ -136,6 +136,10 @@ coder envs --user charlie@coder.com ls -o json \
136
136
func createEnvCmd (user * string )* cobra.Command {
137
137
var (
138
138
org string
139
+ cpu float32
140
+ memory float32
141
+ disk int
142
+ gpus int
139
143
img string
140
144
tag string
141
145
follow bool
@@ -145,14 +149,10 @@ func createEnvCmd(user *string) *cobra.Command {
145
149
Use :"create [environment_name]" ,
146
150
Short :"create a new environment." ,
147
151
Args :cobra .ExactArgs (1 ),
148
- // Don't unhide this command until we can pass image names instead of image id's.
149
- Hidden :true ,
150
- Long :"Create a new environment under the active user." ,
152
+ Long :"Create a new Coder environment." ,
151
153
Example :`# create a new environment using default resource amounts
152
- coder envs create --image 5f443b16-30652892427b955601330fa5 my-env-name
153
-
154
- # create a new environment using custom resource amounts
155
- coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955601330fa5 my-env-name` ,
154
+ coder envs create my-new-env --image ubuntu
155
+ coder envs create my-new-powerfull-env --cpu 12 --disk 100 --memory 16 --image ubuntu` ,
156
156
RunE :func (cmd * cobra.Command ,args []string )error {
157
157
ctx := cmd .Context ()
158
158
if img == "" {
@@ -187,13 +187,11 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
187
187
Name :args [0 ],
188
188
ImageID :importedImg .ID ,
189
189
ImageTag :tag ,
190
+ CPUCores :cpu ,
191
+ MemoryGB :memory ,
192
+ DiskGB :disk ,
193
+ GPUs :gpus ,
190
194
}
191
- // We're explicitly ignoring errors for these because all we
192
- // need to now is if the numeric type is 0 or not.
193
- createReq .CPUCores ,_ = cmd .Flags ().GetFloat32 ("cpu" )
194
- createReq .MemoryGB ,_ = cmd .Flags ().GetFloat32 ("memory" )
195
- createReq .DiskGB ,_ = cmd .Flags ().GetInt ("disk" )
196
- createReq .GPUs ,_ = cmd .Flags ().GetInt ("gpus" )
197
195
198
196
// if any of these defaulted to their zero value we provision
199
197
// the create request with the imported image defaults instead.
@@ -229,10 +227,10 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
229
227
}
230
228
cmd .Flags ().StringVarP (& org ,"org" ,"o" ,"" ,"ID of the organization the environment should be created under." )
231
229
cmd .Flags ().StringVarP (& tag ,"tag" ,"t" ,defaultImgTag ,"tag of the image the environment will be based off of." )
232
- cmd .Flags ().Float32P ( "cpu" ,"c" ,0 ,"number of cpu cores the environment should be provisioned with." )
233
- cmd .Flags ().Float32P ( "memory" ,"m" ,0 ,"GB of RAM an environment should be provisioned with." )
234
- cmd .Flags ().IntP ( "disk" ,"d" ,0 ,"GB of disk storage an environment should be provisioned with." )
235
- cmd .Flags ().IntP ( "gpus" ,"g" ,0 ,"number GPUs an environment should be provisioned with." )
230
+ cmd .Flags ().Float32VarP ( & cpu , "cpu" ,"c" ,0 ,"number of cpu cores the environment should be provisioned with." )
231
+ cmd .Flags ().Float32VarP ( & memory , "memory" ,"m" ,0 ,"GB of RAM an environment should be provisioned with." )
232
+ cmd .Flags ().IntVarP ( & disk , "disk" ,"d" ,0 ,"GB of disk storage an environment should be provisioned with." )
233
+ cmd .Flags ().IntVarP ( & gpus , "gpus" ,"g" ,0 ,"number GPUs an environment should be provisioned with." )
236
234
cmd .Flags ().StringVarP (& img ,"image" ,"i" ,"" ,"name of the image to base the environment off of." )
237
235
cmd .Flags ().BoolVar (& follow ,"follow" ,false ,"follow buildlog after initiating rebuild" )
238
236
_ = cmd .MarkFlagRequired ("image" )
@@ -241,22 +239,21 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
241
239
242
240
func editEnvCmd (user * string )* cobra.Command {
243
241
var (
244
- org string
245
- img string
246
- tag string
247
- cpuCores float32
248
- memGB float32
249
- diskGB int
250
- gpus int
251
- follow bool
242
+ org string
243
+ img string
244
+ tag string
245
+ cpu float32
246
+ memory float32
247
+ disk int
248
+ gpus int
249
+ follow bool
252
250
)
253
251
254
252
cmd := & cobra.Command {
255
- Use :"edit" ,
256
- Short :"edit an existing environment owned by the active user." ,
257
- Args :cobra .ExactArgs (1 ),
258
- Hidden :true ,
259
- Long :"Edit an existing environment owned by the active user." ,
253
+ Use :"edit" ,
254
+ Short :"edit an existing environment and initiate a rebuild." ,
255
+ Args :cobra .ExactArgs (1 ),
256
+ Long :"Edit an existing environment and initate a rebuild." ,
260
257
Example :`coder envs edit back-end-env --cpu 4
261
258
262
259
coder envs edit back-end-env --disk 20` ,
@@ -284,15 +281,10 @@ coder envs edit back-end-env --disk 20`,
284
281
return xerrors .New ("org is required for multi-org members" )
285
282
}
286
283
287
- cpuCores ,_ = cmd .Flags ().GetFloat32 ("cpu" )
288
- memGB ,_ = cmd .Flags ().GetFloat32 ("memory" )
289
- diskGB ,_ = cmd .Flags ().GetInt ("disk" )
290
- gpus ,_ = cmd .Flags ().GetInt ("gpus" )
291
-
292
284
req ,err := buildUpdateReq (ctx ,client ,updateConf {
293
- cpu :cpuCores ,
294
- memGB :memGB ,
295
- diskGB :diskGB ,
285
+ cpu :cpu ,
286
+ memGB :memory ,
287
+ diskGB :disk ,
296
288
gpus :gpus ,
297
289
environment :env ,
298
290
user :user ,
@@ -326,10 +318,10 @@ coder envs edit back-end-env --disk 20`,
326
318
cmd .Flags ().StringVarP (& org ,"org" ,"o" ,"" ,"name of the organization the environment should be created under." )
327
319
cmd .Flags ().StringVarP (& img ,"image" ,"i" ,"" ,"name of the image you want the environment to be based off of." )
328
320
cmd .Flags ().StringVarP (& tag ,"tag" ,"t" ,"latest" ,"image tag of the image you want to base the environment off of." )
329
- cmd .Flags ().Float32P ( "cpu" ,"c" ,cpuCores ,"The number of cpu cores the environment should be provisioned with." )
330
- cmd .Flags ().Float32P ( "memory" ,"m" ,memGB ,"The amount of RAM an environment should be provisioned with." )
331
- cmd .Flags ().IntP ( "disk" ,"d" ,diskGB ,"The amount of disk storage an environment should be provisioned with." )
332
- cmd .Flags ().IntP ( "gpu" ,"g" ,gpus ,"The amount of disk storage to provision the environment with." )
321
+ cmd .Flags ().Float32VarP ( & cpu , "cpu" ,"c" ,0 ,"The number of cpu cores the environment should be provisioned with." )
322
+ cmd .Flags ().Float32VarP ( & memory , "memory" ,"m" ,0 ,"The amount of RAM an environment should be provisioned with." )
323
+ cmd .Flags ().IntVarP ( & disk , "disk" ,"d" ,0 ,"The amount of disk storage an environment should be provisioned with." )
324
+ cmd .Flags ().IntVarP ( & gpus , "gpu" ,"g" ,0 ,"The amount of disk storage to provision the environment with." )
333
325
cmd .Flags ().BoolVar (& follow ,"follow" ,false ,"follow buildlog after initiating rebuild" )
334
326
return cmd
335
327
}