diff --git a/cmd/compose/compose.go b/cmd/compose/compose.go index 15a679f043d..42b7b178d7b 100644 --- a/cmd/compose/compose.go +++ b/cmd/compose/compose.go @@ -622,3 +622,15 @@ var printerModes = []string{ ui.ModePlain, ui.ModeQuiet, } + +func SetUnchangedOption(name string, experimentalFlag bool) bool { + var value bool + // If the var is defined we use that value first + if envVar, ok := os.LookupEnv(name); ok { + value = utils.StringToBool(envVar) + } else { + // if not, we try to get it from experimental feature flag + value = experimentalFlag + } + return value +} diff --git a/cmd/compose/up.go b/cmd/compose/up.go index 5111c0b5761..1b458e3a0d1 100644 --- a/cmd/compose/up.go +++ b/cmd/compose/up.go @@ -42,21 +42,22 @@ type composeOptions struct { type upOptions struct { *composeOptions - Detach bool - noStart bool - noDeps bool - cascadeStop bool - exitCodeFrom string - noColor bool - noPrefix bool - attachDependencies bool - attach []string - noAttach []string - timestamp bool - wait bool - waitTimeout int - watch bool - navigationMenu bool + Detach bool + noStart bool + noDeps bool + cascadeStop bool + exitCodeFrom string + noColor bool + noPrefix bool + attachDependencies bool + attach []string + noAttach []string + timestamp bool + wait bool + waitTimeout int + watch bool + navigationMenu bool + navigationMenuChanged bool } func (opts upOptions) apply(project *types.Project, services []string) (*types.Project, error) { @@ -88,6 +89,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, ex PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error { create.pullChanged = cmd.Flags().Changed("pull") create.timeChanged = cmd.Flags().Changed("timeout") + up.navigationMenuChanged = cmd.Flags().Changed("menu") return validateFlags(&up, &create) }), RunE: p.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error { @@ -129,12 +131,8 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, ex flags.BoolVar(&up.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.") flags.IntVar(&up.waitTimeout, "wait-timeout", 0, "Maximum duration to wait for the project to be running|healthy") flags.BoolVarP(&up.watch, "watch", "w", false, "Watch source code and rebuild/refresh containers when files are updated.") - composeMenu := true - composeMenuEnv, err := utils.GetEnvBool(ComposeMenu) - if err != nil { - composeMenu = composeMenuEnv - } - flags.BoolVar(&up.navigationMenu, "menu", composeMenu, "While running in attach mode, enable helpful shortcuts.") + flags.BoolVar(&up.navigationMenu, "menu", false, "Enable interactive shortcuts when running attached (Experimental). Incompatible with --detach.") + flags.MarkHidden("menu") //nolint:errcheck return upCmd } @@ -168,7 +166,7 @@ func runUp( ctx context.Context, dockerCli command.Cli, backend api.Service, - _ *experimental.State, + experimentals *experimental.State, createOptions createOptions, upOptions upOptions, buildOptions buildOptions, @@ -188,6 +186,9 @@ func runUp( if err != nil { return err } + if !upOptions.navigationMenuChanged { + upOptions.navigationMenu = SetUnchangedOption(ComposeMenu, experimentals.NavBar()) + } var build *api.BuildOptions if !createOptions.noBuild { diff --git a/cmd/formatter/colors.go b/cmd/formatter/colors.go index 0e89af659da..cf6a4b56c37 100644 --- a/cmd/formatter/colors.go +++ b/cmd/formatter/colors.go @@ -42,11 +42,9 @@ const ( UNDERLINE = "4" ) -type Color string - const ( - RESET Color = "0" - CYAN Color = "36" + RESET = "0" + CYAN = "36" ) const ( diff --git a/pkg/utils/stringutils.go b/pkg/utils/stringutils.go index be210154875..1004263bb16 100644 --- a/pkg/utils/stringutils.go +++ b/pkg/utils/stringutils.go @@ -17,8 +17,6 @@ package utils import ( - "fmt" - "os" "strconv" "strings" ) @@ -42,23 +40,3 @@ func StringToBool(s string) bool { b, _ := strconv.ParseBool(s) return b } - -func getEnvStr(key string) (string, error) { - v := os.Getenv(key) - if v == "" { - return v, fmt.Errorf("env var not defined") - } - return v, nil -} - -func GetEnvBool(key string) (bool, error) { - s, err := getEnvStr(key) - if err != nil { - return false, err - } - v, err := strconv.ParseBool(s) - if err != nil { - return false, err - } - return v, nil -}