Skip to content

Commit 5bb4603

Browse files
AnvarUndeloof
authored andcommitted
Set --progress flag default value from env if provided
Signed-off-by: Anvar Umuraliev <an.umuraliev@gmail.com>
1 parent f8dae06 commit 5bb4603

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

cmd/compose/compose.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const (
6969
ComposeEnvFiles = "COMPOSE_ENV_FILES"
7070
// ComposeMenu defines if the navigation menu should be rendered. Can be also set via --menu
7171
ComposeMenu = "COMPOSE_MENU"
72+
// ComposeProgress defines type of progress output, if --progress isn't used
73+
ComposeProgress = "COMPOSE_PROGRESS"
7274
)
7375

7476
// rawEnv load a dot env file using docker/cli key=value parser, without attempt to interpolate or evaluate values
@@ -228,7 +230,7 @@ func (o *ProjectOptions) addProjectFlags(f *pflag.FlagSet) {
228230
f.StringVar(&o.ProjectDir, "project-directory", "", "Specify an alternate working directory\n(default: the path of the, first specified, Compose file)")
229231
f.StringVar(&o.WorkDir, "workdir", "", "DEPRECATED! USE --project-directory INSTEAD.\nSpecify an alternate working directory\n(default: the path of the, first specified, Compose file)")
230232
f.BoolVar(&o.Compatibility, "compatibility", false, "Run compose in backward compatibility mode")
231-
f.StringVar(&o.Progress, "progress", string(buildkit.AutoMode), fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))
233+
f.StringVar(&o.Progress, "progress", defaultStringVar(ComposeProgress, string(buildkit.AutoMode)), fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))
232234
f.BoolVar(&o.All, "all-resources", false, "Include all resources, even those not used by services")
233235
_ = f.MarkHidden("workdir")
234236
}
@@ -240,6 +242,14 @@ func defaultStringArrayVar(env string) []string {
240242
})
241243
}
242244

245+
// get default value for a command line flag from the env variable, if the env variable is not set, it returns the provided default value 'def'
246+
func defaultStringVar(env, def string) string {
247+
if v, ok := os.LookupEnv(env); ok {
248+
return v
249+
}
250+
return def
251+
}
252+
243253
func (o *ProjectOptions) projectOrName(ctx context.Context, dockerCli command.Cli, services ...string) (*types.Project, string, error) {
244254
name := o.ProjectName
245255
var project *types.Project

pkg/progress/writer.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package progress
1919
import (
2020
"context"
2121
"io"
22-
"os"
2322
"sync"
2423

2524
"github.com/docker/cli/cli/streams"
@@ -122,9 +121,6 @@ func NewWriter(ctx context.Context, out *streams.Out, progressTitle string) (Wri
122121
if !ok {
123122
dryRun = false
124123
}
125-
if v, ok := os.LookupEnv("COMPOSE_PROGRESS"); ok && Mode == ModeAuto {
126-
Mode = v
127-
}
128124
if Mode == ModeQuiet {
129125
return quiet{}, nil
130126
}

0 commit comments

Comments
 (0)