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

Commit 1b2e46d

Browse files
committed
Style cleanup
1 parent 9ead247 commit 1b2e46d

File tree

2 files changed

+35
-50
lines changed

2 files changed

+35
-50
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
type findImgConf struct {
87-
client *coder.Client
8887
email string
8988
imgName string
9089
orgName string
9190
}
9291

93-
func findImg(ctx context.Context, conf findImgConf) (*coder.Image, error) {
92+
func findImg(ctx context.Context, client *coder.Client, conf findImgConf) (*coder.Image, error) {
9493
switch {
9594
case conf.email == "":
9695
return nil, xerrors.New("user email unset")
9796
case conf.imgName == "":
9897
return nil, 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
if err != nil {
109105
return nil, err
110106
}
@@ -129,38 +125,37 @@ func findImg(ctx context.Context, conf findImgConf) (*coder.Image, error) {
129125
return nil, 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 := range possibleMatches {
135-
lines = append(lines, img.Repository)
131+
lines = append(lines, fmt.Sprintf(" %s", img.Repository))
136132
}
137133
return nil, 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
type getImgsConf struct {
144-
client *coder.Client
145140
email string
146141
orgName string
147142
}
148143

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

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

160155
orgs = lookupUserOrgs(u, orgs)
161156

162157
for _, org := range orgs {
163-
imgs, err := conf.client.OrganizationImages(ctx, org.ID)
158+
imgs, err := client.OrganizationImages(ctx, org.ID)
164159
if err != nil {
165160
return nil, err
166161
}

internal/cmd/envs.go

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,11 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
173173
return xerrors.New("org is required for multi-org members")
174174
}
175175

176-
importedImg, err := findImg(ctx,
177-
findImgConf{
178-
client: client,
179-
email: *user,
180-
imgName: img,
181-
orgName: org,
182-
},
183-
)
176+
importedImg, err := findImg(ctx, client, findImgConf{
177+
email: *user,
178+
imgName: img,
179+
orgName: org,
180+
})
184181
if err != nil {
185182
return err
186183
}
@@ -225,7 +222,7 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
225222

226223
clog.LogSuccess("creating environment...",
227224
clog.BlankLine,
228-
clog.Tipf(`run "coder envs watch-build %q" to trail the build logs`, env.Name),
225+
clog.Tipf(`run "coder envs watch-build %s" to trail the build logs`, env.Name),
229226
)
230227
return nil
231228
},
@@ -292,20 +289,17 @@ coder envs edit back-end-env --disk 20`,
292289
diskGB, _ = cmd.Flags().GetInt("disk")
293290
gpus, _ = cmd.Flags().GetInt("gpus")
294291

295-
req, err := buildUpdateReq(ctx,
296-
updateConf{
297-
cpu: cpuCores,
298-
memGB: memGB,
299-
diskGB: diskGB,
300-
gpus: gpus,
301-
client: client,
302-
environment: env,
303-
user: user,
304-
image: img,
305-
imageTag: tag,
306-
orgName: org,
307-
},
308-
)
292+
req, err := buildUpdateReq(ctx, client, updateConf{
293+
cpu: cpuCores,
294+
memGB: memGB,
295+
diskGB: diskGB,
296+
gpus: gpus,
297+
environment: env,
298+
user: user,
299+
image: img,
300+
imageTag: tag,
301+
orgName: org,
302+
})
309303
if err != nil {
310304
return err
311305
}
@@ -324,7 +318,7 @@ coder envs edit back-end-env --disk 20`,
324318

325319
clog.LogSuccess("applied changes to the environment, rebuilding...",
326320
clog.BlankLine,
327-
clog.Tipf(`run "coder envs watch-build %q" to trail the build logs`, envName),
321+
clog.Tipf(`run "coder envs watch-build %s" to trail the build logs`, envName),
328322
)
329323
return nil
330324
},
@@ -359,7 +353,7 @@ func rmEnvsCmd(user *string) *cobra.Command {
359353
}
360354
if _, err := confirm.Run(); err != nil {
361355
return clog.Fatal(
362-
"failed to confirm prompt", clog.BlankLine,
356+
"failed to confirm deletion", clog.BlankLine,
363357
clog.Tipf(`use "--force" to rebuild without a confirmation prompt`),
364358
)
365359
}
@@ -395,15 +389,14 @@ type updateConf struct {
395389
memGB float32
396390
diskGB int
397391
gpus int
398-
client *coder.Client
399392
environment *coder.Environment
400393
user *string
401394
image string
402395
imageTag string
403396
orgName string
404397
}
405398

406-
func buildUpdateReq(ctx context.Context, conf updateConf) (*coder.UpdateEnvironmentReq, error) {
399+
func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf) (*coder.UpdateEnvironmentReq, error) {
407400
var (
408401
updateReq coder.UpdateEnvironmentReq
409402
defaultCPUCores float32
@@ -413,14 +406,11 @@ func buildUpdateReq(ctx context.Context, conf updateConf) (*coder.UpdateEnvironm
413406

414407
// If this is not empty it means the user is requesting to change the environment image.
415408
if conf.image != "" {
416-
importedImg, err := findImg(ctx,
417-
findImgConf{
418-
client: conf.client,
419-
email: *conf.user,
420-
imgName: conf.image,
421-
orgName: conf.orgName,
422-
},
423-
)
409+
importedImg, err := findImg(ctx, client, findImgConf{
410+
email: *conf.user,
411+
imgName: conf.image,
412+
orgName: conf.orgName,
413+
})
424414
if err != nil {
425415
return nil, err
426416
}

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