Skip to content

Commit 5f76cb5

Browse files
nervghalexey-igrychev
authored andcommitted
feat(client): support more envs for trdl update
Signed-off-by: Alexandr Zaytsev <alexandr.zaytsev@flant.com>
1 parent 34401f6 commit 5f76cb5

File tree

7 files changed

+216
-654
lines changed

7 files changed

+216
-654
lines changed

client/cmd/trdl/common.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package main
22

33
import (
44
"fmt"
5-
"os"
65
"strings"
76

87
"github.com/asaskevich/govalidator"
98
"github.com/spf13/cobra"
109

10+
"github.com/werf/common-go/pkg/util"
1111
"github.com/werf/trdl/client/pkg/trdl"
1212
)
1313

@@ -22,16 +22,12 @@ func ValidateChannel(channel string) error {
2222
}
2323

2424
func SetupNoSelfUpdate(cmd *cobra.Command, noSelfUpdate *bool) {
25-
cmd.Flags().BoolVar(noSelfUpdate, "no-self-update", GetBoolEnvironmentDefaultFalse("TRDL_NO_SELF_UPDATE"), "Do not perform self-update (default $TRDL_NO_SELF_UPDATE or false)")
26-
}
25+
envKey := "TRDL_NO_SELF_UPDATE"
2726

28-
func GetBoolEnvironmentDefaultFalse(environmentName string) bool {
29-
switch os.Getenv(environmentName) {
30-
case "1", "true", "yes":
31-
return true
32-
default:
33-
return false
34-
}
27+
cmd.Flags().BoolVar(noSelfUpdate,
28+
"no-self-update",
29+
util.GetBoolEnvironmentDefaultFalse(envKey),
30+
fmt.Sprintf("Do not perform self-update (default $%s or false)", envKey))
3531
}
3632

3733
func PrintHelp(cmd *cobra.Command) {

client/cmd/trdl/update.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/spf13/cobra"
1010

11+
"github.com/werf/common-go/pkg/util"
1112
trdlClient "github.com/werf/trdl/client/pkg/client"
1213
"github.com/werf/trdl/client/pkg/trdl"
1314
)
@@ -85,10 +86,10 @@ func updateCmd() *cobra.Command {
8586
}
8687

8788
SetupNoSelfUpdate(cmd, &noSelfUpdate)
88-
cmd.Flags().BoolVar(&autoclean, "autoclean", true, "Erase old downloaded releases")
89-
cmd.Flags().BoolVar(&inBackground, "in-background", false, "Perform update in background")
90-
cmd.Flags().StringVarP(&backgroundStdoutFile, "background-stdout-file", "", "", "Redirect the stdout of the background update to a file")
91-
cmd.Flags().StringVarP(&backgroundStderrFile, "background-stderr-file", "", "", "Redirect the stderr of the background update to a file")
89+
setupAutoclean(cmd, &autoclean)
90+
setupInBackground(cmd, &inBackground)
91+
setupBackgroundStdoutFile(cmd, &backgroundStdoutFile)
92+
setupBackgroundStderrFile(cmd, &backgroundStderrFile)
9293

9394
return cmd
9495
}
@@ -127,3 +128,41 @@ func StartUpdateInBackground(name string, args []string, backgroundStdoutFile, b
127128

128129
return nil
129130
}
131+
132+
func setupAutoclean(cmd *cobra.Command, autoclean *bool) {
133+
envKey := "TRDL_AUTOCLEAN"
134+
135+
cmd.Flags().BoolVar(autoclean,
136+
"autoclean",
137+
util.GetBoolEnvironmentDefaultTrue(envKey),
138+
fmt.Sprintf("Erase old downloaded releases (default $%s or true)", envKey))
139+
}
140+
141+
func setupInBackground(cmd *cobra.Command, inBackground *bool) {
142+
envKey := "TRDL_IN_BACKGROUND"
143+
144+
cmd.Flags().BoolVar(inBackground,
145+
"in-background",
146+
util.GetBoolEnvironmentDefaultFalse(envKey),
147+
fmt.Sprintf("Perform update in background (default $%s or false)", envKey))
148+
}
149+
150+
func setupBackgroundStdoutFile(cmd *cobra.Command, backgroundStdoutFile *string) {
151+
envKey := "TRDL_BACKGROUND_STDOUT_FILE"
152+
153+
cmd.Flags().StringVarP(backgroundStdoutFile,
154+
"background-stdout-file",
155+
"",
156+
os.Getenv(envKey),
157+
fmt.Sprintf("Redirect the stdout of the background update to a file (default $%s or none)", envKey))
158+
}
159+
160+
func setupBackgroundStderrFile(cmd *cobra.Command, backgroundStderrFile *string) {
161+
envKey := "TRDL_BACKGROUND_STDERR_FILE"
162+
163+
cmd.Flags().StringVarP(backgroundStderrFile,
164+
"background-stderr-file",
165+
"",
166+
os.Getenv(envKey),
167+
fmt.Sprintf("Redirect the stderr of the background update to a file (default $%s or none)", envKey))
168+
}

client/go.mod

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,41 @@ go 1.23
55
require (
66
bou.ke/monkey v1.0.2
77
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
8-
github.com/gookit/color v1.5.2
8+
github.com/gookit/color v1.5.4
99
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
1010
github.com/rodaine/table v1.1.0
1111
github.com/spaolacci/murmur3 v1.1.0
12-
github.com/spf13/cobra v1.6.1
12+
github.com/spf13/cobra v1.8.0
1313
github.com/spf13/pflag v1.0.5
1414
github.com/theupdateframework/go-tuf v0.5.2
15+
github.com/werf/common-go v0.0.0-20250225170837-c0fe1ae7c6a2
1516
github.com/werf/lockgate v0.1.1
16-
github.com/werf/logboek v0.5.5
17+
github.com/werf/logboek v0.6.1
1718
gopkg.in/yaml.v3 v3.0.1
1819
mvdan.cc/xurls v1.1.0
1920
)
2021

2122
require (
2223
github.com/avelino/slugify v0.0.0-20180501145920-855f152bd774 // indirect
24+
github.com/djherbis/buffer v1.2.0 // indirect
25+
github.com/djherbis/nio/v3 v3.0.1 // indirect
26+
github.com/go-git/go-git/v5 v5.12.0 // indirect
2327
github.com/gofrs/flock v0.8.1 // indirect
2428
github.com/golang/snappy v0.0.4 // indirect
25-
github.com/google/uuid v1.3.0 // indirect
26-
github.com/inconshreveable/mousetrap v1.0.1 // indirect
29+
github.com/google/uuid v1.6.0 // indirect
30+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2731
github.com/mvdan/xurls v1.1.0 // indirect
32+
github.com/pjbgf/sha1cd v0.3.0 // indirect
2833
github.com/secure-systems-lab/go-securesystemslib v0.4.0 // indirect
2934
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
30-
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
31-
golang.org/x/crypto v0.7.0 // indirect
32-
golang.org/x/net v0.8.0 // indirect
33-
golang.org/x/sys v0.6.0 // indirect
34-
golang.org/x/term v0.6.0 // indirect
35-
golang.org/x/text v0.8.0 // indirect
35+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
36+
golang.org/x/crypto v0.31.0 // indirect
37+
golang.org/x/mod v0.21.0 // indirect
38+
golang.org/x/net v0.33.0 // indirect
39+
golang.org/x/sys v0.28.0 // indirect
40+
golang.org/x/term v0.27.0 // indirect
41+
golang.org/x/text v0.21.0 // indirect
42+
sigs.k8s.io/yaml v1.4.0 // indirect
3643
)
3744

3845
replace github.com/theupdateframework/go-tuf => github.com/werf/3p-go-tuf v0.0.0-20230315082915-5fc159235553

0 commit comments

Comments
 (0)