Skip to content

Commit d0ce3bb

Browse files
committed
add feature flag from DD
Signed-off-by: Joana Hrotko <[email protected]>
1 parent ea20ba4 commit d0ce3bb

File tree

4 files changed

+37
-48
lines changed

4 files changed

+37
-48
lines changed

Diff for: cmd/compose/compose.go

+12
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,15 @@ var printerModes = []string{
622622
ui.ModePlain,
623623
ui.ModeQuiet,
624624
}
625+
626+
func SetUnchangedOption(name string, experimentalFlag bool) bool {
627+
var value bool
628+
// If the var is defined we use that value first
629+
if envVar, ok := os.LookupEnv(name); ok {
630+
value = utils.StringToBool(envVar)
631+
} else {
632+
// if not, we try to get it from experimental feature flag
633+
value = experimentalFlag
634+
}
635+
return value
636+
}

Diff for: cmd/compose/up.go

+23-22
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,22 @@ type composeOptions struct {
4242

4343
type upOptions struct {
4444
*composeOptions
45-
Detach bool
46-
noStart bool
47-
noDeps bool
48-
cascadeStop bool
49-
exitCodeFrom string
50-
noColor bool
51-
noPrefix bool
52-
attachDependencies bool
53-
attach []string
54-
noAttach []string
55-
timestamp bool
56-
wait bool
57-
waitTimeout int
58-
watch bool
59-
navigationMenu bool
45+
Detach bool
46+
noStart bool
47+
noDeps bool
48+
cascadeStop bool
49+
exitCodeFrom string
50+
noColor bool
51+
noPrefix bool
52+
attachDependencies bool
53+
attach []string
54+
noAttach []string
55+
timestamp bool
56+
wait bool
57+
waitTimeout int
58+
watch bool
59+
navigationMenu bool
60+
navigationMenuChanged bool
6061
}
6162

6263
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
8889
PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
8990
create.pullChanged = cmd.Flags().Changed("pull")
9091
create.timeChanged = cmd.Flags().Changed("timeout")
92+
up.navigationMenuChanged = cmd.Flags().Changed("menu")
9193
return validateFlags(&up, &create)
9294
}),
9395
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
129131
flags.BoolVar(&up.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.")
130132
flags.IntVar(&up.waitTimeout, "wait-timeout", 0, "Maximum duration to wait for the project to be running|healthy")
131133
flags.BoolVarP(&up.watch, "watch", "w", false, "Watch source code and rebuild/refresh containers when files are updated.")
132-
composeMenu := true
133-
composeMenuEnv, err := utils.GetEnvBool(ComposeMenu)
134-
if err != nil {
135-
composeMenu = composeMenuEnv
136-
}
137-
flags.BoolVar(&up.navigationMenu, "menu", composeMenu, "While running in attach mode, enable helpful shortcuts.")
134+
flags.BoolVar(&up.navigationMenu, "menu", false, "Enable interactive shortcuts when running attached (Experimental). Incompatible with --detach.")
135+
flags.MarkHidden("menu") //nolint:errcheck
138136

139137
return upCmd
140138
}
@@ -168,7 +166,7 @@ func runUp(
168166
ctx context.Context,
169167
dockerCli command.Cli,
170168
backend api.Service,
171-
_ *experimental.State,
169+
experimentals *experimental.State,
172170
createOptions createOptions,
173171
upOptions upOptions,
174172
buildOptions buildOptions,
@@ -188,6 +186,9 @@ func runUp(
188186
if err != nil {
189187
return err
190188
}
189+
if !upOptions.navigationMenuChanged {
190+
upOptions.navigationMenu = SetUnchangedOption(ComposeMenu, experimentals.NavBar())
191+
}
191192

192193
var build *api.BuildOptions
193194
if !createOptions.noBuild {

Diff for: cmd/formatter/colors.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ const (
4242
UNDERLINE = "4"
4343
)
4444

45-
type Color string
46-
4745
const (
48-
RESET Color = "0"
49-
CYAN Color = "36"
46+
RESET = "0"
47+
CYAN = "36"
5048
)
5149

5250
const (

Diff for: pkg/utils/stringutils.go

-22
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package utils
1818

1919
import (
20-
"fmt"
21-
"os"
2220
"strconv"
2321
"strings"
2422
)
@@ -42,23 +40,3 @@ func StringToBool(s string) bool {
4240
b, _ := strconv.ParseBool(s)
4341
return b
4442
}
45-
46-
func getEnvStr(key string) (string, error) {
47-
v := os.Getenv(key)
48-
if v == "" {
49-
return v, fmt.Errorf("env var not defined")
50-
}
51-
return v, nil
52-
}
53-
54-
func GetEnvBool(key string) (bool, error) {
55-
s, err := getEnvStr(key)
56-
if err != nil {
57-
return false, err
58-
}
59-
v, err := strconv.ParseBool(s)
60-
if err != nil {
61-
return false, err
62-
}
63-
return v, nil
64-
}

0 commit comments

Comments
 (0)