|
8 | 8 |
|
9 | 9 | "github.com/spf13/cobra" |
10 | 10 |
|
| 11 | + "github.com/werf/common-go/pkg/util" |
11 | 12 | trdlClient "github.com/werf/trdl/client/pkg/client" |
12 | 13 | "github.com/werf/trdl/client/pkg/trdl" |
13 | 14 | ) |
@@ -85,10 +86,10 @@ func updateCmd() *cobra.Command { |
85 | 86 | } |
86 | 87 |
|
87 | 88 | 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) |
92 | 93 |
|
93 | 94 | return cmd |
94 | 95 | } |
@@ -127,3 +128,41 @@ func StartUpdateInBackground(name string, args []string, backgroundStdoutFile, b |
127 | 128 |
|
128 | 129 | return nil |
129 | 130 | } |
| 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 | +} |
0 commit comments