Skip to content

Commit

Permalink
add feature flag from DD
Browse files Browse the repository at this point in the history
Signed-off-by: Joana Hrotko <joana.hrotko@docker.com>
  • Loading branch information
jhrotko committed Mar 20, 2024
1 parent 610917c commit 68d5908
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 48 deletions.
12 changes: 12 additions & 0 deletions cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
45 changes: 23 additions & 22 deletions cmd/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions cmd/formatter/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ const (
UNDERLINE = "4"
)

type Color string

const (
RESET Color = "0"
CYAN Color = "36"
RESET = "0"
CYAN = "36"
)

const (
Expand Down
22 changes: 0 additions & 22 deletions pkg/utils/stringutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package utils

import (
"fmt"
"os"
"strconv"
"strings"
)
Expand All @@ -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
}

0 comments on commit 68d5908

Please sign in to comment.