Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit feb3ab3

Browse files
committed
fixup! Style cleanup
1 parent 1b2e46d commit feb3ab3

File tree

1 file changed

+34
-42
lines changed

1 file changed

+34
-42
lines changed

internal/cmd/envs.go

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ coder envs --user charlie@coder.com ls -o json \
136136
func createEnvCmd(user *string) *cobra.Command {
137137
var (
138138
org string
139+
cpu float32
140+
memory float32
141+
disk int
142+
gpus int
139143
img string
140144
tag string
141145
follow bool
@@ -145,14 +149,10 @@ func createEnvCmd(user *string) *cobra.Command {
145149
Use: "create [environment_name]",
146150
Short: "create a new environment.",
147151
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.",
151153
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`,
156156
RunE: func(cmd *cobra.Command, args []string) error {
157157
ctx := cmd.Context()
158158
if img == "" {
@@ -187,13 +187,11 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
187187
Name: args[0],
188188
ImageID: importedImg.ID,
189189
ImageTag: tag,
190+
CPUCores: cpu,
191+
MemoryGB: memory,
192+
DiskGB: disk,
193+
GPUs: gpus,
190194
}
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")
197195

198196
// if any of these defaulted to their zero value we provision
199197
// 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
229227
}
230228
cmd.Flags().StringVarP(&org, "org", "o", "", "ID of the organization the environment should be created under.")
231229
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.")
236234
cmd.Flags().StringVarP(&img, "image", "i", "", "name of the image to base the environment off of.")
237235
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
238236
_ = cmd.MarkFlagRequired("image")
@@ -241,22 +239,21 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
241239

242240
func editEnvCmd(user *string) *cobra.Command {
243241
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
252250
)
253251

254252
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.",
260257
Example: `coder envs edit back-end-env --cpu 4
261258
262259
coder envs edit back-end-env --disk 20`,
@@ -284,15 +281,10 @@ coder envs edit back-end-env --disk 20`,
284281
return xerrors.New("org is required for multi-org members")
285282
}
286283

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-
292284
req, err := buildUpdateReq(ctx, client, updateConf{
293-
cpu: cpuCores,
294-
memGB: memGB,
295-
diskGB: diskGB,
285+
cpu: cpu,
286+
memGB: memory,
287+
diskGB: disk,
296288
gpus: gpus,
297289
environment: env,
298290
user: user,
@@ -326,10 +318,10 @@ coder envs edit back-end-env --disk 20`,
326318
cmd.Flags().StringVarP(&org, "org", "o", "", "name of the organization the environment should be created under.")
327319
cmd.Flags().StringVarP(&img, "image", "i", "", "name of the image you want the environment to be based off of.")
328320
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.")
333325
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
334326
return cmd
335327
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy