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

Commit 40f521c

Browse files
author
Faris Huskovic
committed
dont pass cobra command down stream in updateConf
1 parent 085971c commit 40f521c

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

internal/cmd/envs.go

+29-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"os"
@@ -280,13 +281,23 @@ coder envs edit back-end-env --disk 20`,
280281
return err
281282
}
282283

283-
req, err := buildUpdateReq(updateConf{
284-
command: cmd,
284+
cpuCores, _ = cmd.Flags().GetFloat32("cpu")
285+
memGB, _ = cmd.Flags().GetFloat32("memory")
286+
diskGB, _ = cmd.Flags().GetInt("disk")
287+
gpus, _ = cmd.Flags().GetInt("gpus")
288+
289+
req, err := buildUpdateReq(cmd.Context(),
290+
updateConf{
291+
cpu: cpuCores,
292+
memGB: memGB,
293+
diskGB: diskGB,
294+
gpus: gpus,
285295
client: client,
286296
environment: env,
287297
user: user,
288298
image: img,
289299
imageTag: tag,
300+
orgName: org,
290301
},
291302
)
292303
if err != nil {
@@ -394,15 +405,19 @@ func rmEnvsCommand(user *string) *cobra.Command {
394405
}
395406

396407
type updateConf struct {
397-
command *cobra.Command
408+
cpu float32
409+
memGB float32
410+
diskGB int
411+
gpus int
398412
client *coder.Client
399413
environment *coder.Environment
400414
user *string
401415
image string
402416
imageTag string
417+
orgName string
403418
}
404419

405-
func buildUpdateReq(conf updateConf) (*coder.UpdateEnvironmentReq, error) {
420+
func buildUpdateReq(ctx context.Context, conf updateConf) (*coder.UpdateEnvironmentReq, error) {
406421
var (
407422
updateReq coder.UpdateEnvironmentReq
408423
defaultCPUCores float32
@@ -412,10 +427,11 @@ func buildUpdateReq(conf updateConf) (*coder.UpdateEnvironmentReq, error) {
412427

413428
// If this is not empty it means the user is requesting to change the environment image.
414429
if conf.image != "" {
415-
importedImg, err := findImg(conf.command.Context(),
430+
importedImg, err := findImg(ctx,
416431
conf.client,
417432
*conf.user,
418433
conf.image,
434+
conf.orgName,
419435
)
420436
if err != nil {
421437
return nil, err
@@ -449,25 +465,22 @@ func buildUpdateReq(conf updateConf) (*coder.UpdateEnvironmentReq, error) {
449465
// If they did not, then we will get the zero value back
450466
// and should set the resource amount to the default.
451467

452-
cpuCores, _ := conf.command.Flags().GetFloat32("cpu")
453-
if cpuCores == 0 {
468+
if conf.cpu == 0 {
454469
updateReq.CPUCores = &defaultCPUCores
455470
} else {
456-
updateReq.CPUCores = &cpuCores
471+
updateReq.CPUCores = &conf.cpu
457472
}
458473

459-
memGB, _ := conf.command.Flags().GetFloat32("memory")
460-
if memGB == 0 {
474+
if conf.memGB == 0 {
461475
updateReq.MemoryGB = &defaultMemGB
462476
} else {
463-
updateReq.MemoryGB = &memGB
477+
updateReq.MemoryGB = &conf.memGB
464478
}
465479

466-
diskGB, _ := conf.command.Flags().GetInt("disk")
467-
if diskGB == 0 {
480+
if conf.diskGB == 0 {
468481
updateReq.DiskGB = &defaultDiskGB
469482
} else {
470-
updateReq.DiskGB = &diskGB
483+
updateReq.DiskGB = &conf.diskGB
471484
}
472485

473486
// Environment disks can not be shrink so we have to overwrite this
@@ -477,9 +490,8 @@ func buildUpdateReq(conf updateConf) (*coder.UpdateEnvironmentReq, error) {
477490
updateReq.DiskGB = &conf.environment.DiskGB
478491
}
479492

480-
gpus, _ := conf.command.Flags().GetInt("gpus")
481-
if gpus != 0 {
482-
updateReq.GPUs = &gpus
493+
if conf.gpus != 0 {
494+
updateReq.GPUs = &conf.gpus
483495
}
484496

485497
if conf.imageTag == "" {

0 commit comments

Comments
 (0)