Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit806e190

Browse files
committed
Style cleanup
1 parent258f3e1 commit806e190

File tree

2 files changed

+66
-89
lines changed

2 files changed

+66
-89
lines changed

‎internal/cmd/ceapi.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,23 @@ func findEnv(ctx context.Context, client *coder.Client, envName, userEmail strin
8484
}
8585

8686
typefindImgConfstruct {
87-
client*coder.Client
8887
emailstring
8988
imgNamestring
9089
orgNamestring
9190
}
9291

93-
funcfindImg(ctx context.Context,conffindImgConf) (*coder.Image,error) {
92+
funcfindImg(ctx context.Context,client*coder.Client,conffindImgConf) (*coder.Image,error) {
9493
switch {
9594
caseconf.email=="":
9695
returnnil,xerrors.New("user email unset")
9796
caseconf.imgName=="":
9897
returnnil,xerrors.New("image name unset")
9998
}
10099

101-
imgs,err:=getImgs(ctx,
102-
getImgsConf{
103-
client:conf.client,
100+
imgs,err:=getImgs(ctx,client,getImgsConf{
104101
email:conf.email,
105102
orgName:conf.orgName,
106-
},
107-
)
103+
})
108104
iferr!=nil {
109105
returnnil,err
110106
}
@@ -129,38 +125,37 @@ func findImg(ctx context.Context, conf findImgConf) (*coder.Image, error) {
129125
returnnil,xerrors.New("image not found - did you forget to import this image?")
130126
}
131127

132-
lines:= []string{clog.Tipf("Did you mean?")}
128+
lines:= []string{clog.Hintf("Did you mean?")}
133129

134130
for_,img:=rangepossibleMatches {
135-
lines=append(lines,img.Repository)
131+
lines=append(lines,fmt.Sprintf(" %s",img.Repository))
136132
}
137133
returnnil,clog.Fatal(
138-
fmt.Sprintf("Found %d possible matches for %q.",len(possibleMatches),conf.imgName),
134+
fmt.Sprintf("image %s not found",conf.imgName),
139135
lines...,
140136
)
141137
}
142138

143139
typegetImgsConfstruct {
144-
client*coder.Client
145140
emailstring
146141
orgNamestring
147142
}
148143

149-
funcgetImgs(ctx context.Context,confgetImgsConf) ([]coder.Image,error) {
150-
u,err:=conf.client.UserByEmail(ctx,conf.email)
144+
funcgetImgs(ctx context.Context,client*coder.Client,confgetImgsConf) ([]coder.Image,error) {
145+
u,err:=client.UserByEmail(ctx,conf.email)
151146
iferr!=nil {
152147
returnnil,err
153148
}
154149

155-
orgs,err:=conf.client.Organizations(ctx)
150+
orgs,err:=client.Organizations(ctx)
156151
iferr!=nil {
157152
returnnil,err
158153
}
159154

160155
orgs=lookupUserOrgs(u,orgs)
161156

162157
for_,org:=rangeorgs {
163-
imgs,err:=conf.client.OrganizationImages(ctx,org.ID)
158+
imgs,err:=client.OrganizationImages(ctx,org.ID)
164159
iferr!=nil {
165160
returnnil,err
166161
}

‎internal/cmd/envs.go

Lines changed: 56 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ coder envs --user charlie@coder.com ls -o json \
141141
funccreateEnvCmd(user*string)*cobra.Command {
142142
var (
143143
orgstring
144+
cpufloat32
145+
memoryfloat32
146+
diskint
147+
gpusint
144148
imgstring
145149
tagstring
146150
followbool
@@ -150,14 +154,10 @@ func createEnvCmd(user *string) *cobra.Command {
150154
Use:"create [environment_name]",
151155
Short:"create a new environment.",
152156
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.",
156158
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`,
161161
RunE:func(cmd*cobra.Command,args []string)error {
162162
ctx:=cmd.Context()
163163
ifimg=="" {
@@ -178,14 +178,11 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
178178
returnxerrors.New("org is required for multi-org members")
179179
}
180180

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+
})
189186
iferr!=nil {
190187
returnerr
191188
}
@@ -195,13 +192,11 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
195192
Name:args[0],
196193
ImageID:importedImg.ID,
197194
ImageTag:tag,
195+
CPUCores:cpu,
196+
MemoryGB:memory,
197+
DiskGB:disk,
198+
GPUs:gpus,
198199
}
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")
205200

206201
// if any of these defaulted to their zero value we provision
207202
// 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
230225

231226
clog.LogSuccess("creating environment...",
232227
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),
234229
)
235230
returnnil
236231
},
237232
}
238233
cmd.Flags().StringVarP(&org,"org","o","","ID of the organization the environment should be created under.")
239234
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.")
244239
cmd.Flags().StringVarP(&img,"image","i","","name of the image to base the environment off of.")
245240
cmd.Flags().BoolVar(&follow,"follow",false,"follow buildlog after initiating rebuild")
246241
_=cmd.MarkFlagRequired("image")
@@ -249,22 +244,21 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
249244

250245
funceditEnvCmd(user*string)*cobra.Command {
251246
var (
252-
orgstring
253-
imgstring
254-
tagstring
255-
cpuCoresfloat32
256-
memGBfloat32
257-
diskGBint
258-
gpusint
259-
followbool
247+
orgstring
248+
imgstring
249+
tagstring
250+
cpufloat32
251+
memoryfloat32
252+
diskint
253+
gpusint
254+
followbool
260255
)
261256

262257
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.",
268262
Example:`coder envs edit back-end-env --cpu 4
269263
270264
coder envs edit back-end-env --disk 20`,
@@ -292,25 +286,17 @@ coder envs edit back-end-env --disk 20`,
292286
returnxerrors.New("org is required for multi-org members")
293287
}
294288

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+
})
314300
iferr!=nil {
315301
returnerr
316302
}
@@ -329,18 +315,18 @@ coder envs edit back-end-env --disk 20`,
329315

330316
clog.LogSuccess("applied changes to the environment, rebuilding...",
331317
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),
333319
)
334320
returnnil
335321
},
336322
}
337323
cmd.Flags().StringVarP(&org,"org","o","","name of the organization the environment should be created under.")
338324
cmd.Flags().StringVarP(&img,"image","i","","name of the image you want the environment to be based off of.")
339325
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.")
344330
cmd.Flags().BoolVar(&follow,"follow",false,"follow buildlog after initiating rebuild")
345331
returncmd
346332
}
@@ -364,7 +350,7 @@ func rmEnvsCmd(user *string) *cobra.Command {
364350
}
365351
if_,err:=confirm.Run();err!=nil {
366352
returnclog.Fatal(
367-
"failed to confirmprompt",clog.BlankLine,
353+
"failed to confirmdeletion",clog.BlankLine,
368354
clog.Tipf(`use "--force" to rebuild without a confirmation prompt`),
369355
)
370356
}
@@ -400,15 +386,14 @@ type updateConf struct {
400386
memGBfloat32
401387
diskGBint
402388
gpusint
403-
client*coder.Client
404389
environment*coder.Environment
405390
user*string
406391
imagestring
407392
imageTagstring
408393
orgNamestring
409394
}
410395

411-
funcbuildUpdateReq(ctx context.Context,confupdateConf) (*coder.UpdateEnvironmentReq,error) {
396+
funcbuildUpdateReq(ctx context.Context,client*coder.Client,confupdateConf) (*coder.UpdateEnvironmentReq,error) {
412397
var (
413398
updateReq coder.UpdateEnvironmentReq
414399
defaultCPUCoresfloat32
@@ -418,14 +403,11 @@ func buildUpdateReq(ctx context.Context, conf updateConf) (*coder.UpdateEnvironm
418403

419404
// If this is not empty it means the user is requesting to change the environment image.
420405
ifconf.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+
})
429411
iferr!=nil {
430412
returnnil,err
431413
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp