Skip to content

Commit 4ed8a30

Browse files
committed
Fix typo
Signed-off-by: Joana Hrotko <[email protected]>
1 parent 0c09cc9 commit 4ed8a30

File tree

16 files changed

+220
-145
lines changed

16 files changed

+220
-145
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ RUN --mount=type=bind,target=. \
101101
FROM build-base AS test
102102
ARG CGO_ENABLED=0
103103
ARG BUILD_TAGS
104+
ENV COMPOSE_MENU=FALSE
104105
RUN --mount=type=bind,target=. \
105106
--mount=type=cache,target=/root/.cache \
106107
--mount=type=cache,target=/go/pkg/mod \

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
PKG := github.com/docker/compose/v2
16+
export COMPOSE_MENU = FALSE
1617
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
1718

1819
GO_LDFLAGS ?= -w -X ${PKG}/internal.Version=${VERSION}

cmd/compose/compose.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const (
6565
ComposeIgnoreOrphans = "COMPOSE_IGNORE_ORPHANS"
6666
// ComposeEnvFiles defines the env files to use if --env-file isn't used
6767
ComposeEnvFiles = "COMPOSE_ENV_FILES"
68-
// ComposeMenu defines if the navigation menu should be rendered. Can be also set via --navigation-menu
68+
// ComposeMenu defines if the navigation menu should be rendered. Can be also set via --menu
6969
ComposeMenu = "COMPOSE_MENU"
7070
)
7171

@@ -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+
}

cmd/compose/up.go

+33-31
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,11 +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-
if os.Getenv(ComposeMenu) != "" {
134-
composeMenu = utils.StringToBool(os.Getenv(ComposeMenu))
135-
}
136-
flags.BoolVar(&up.navigationMenu, "navigation-menu", composeMenu, "While running in attach mode, enable shortcuts and shortcuts info bar.")
134+
flags.BoolVar(&up.navigationMenu, "menu", false, "Enable interactive shortcuts when running attached (Experimental). Incompatible with --detach.")
135+
flags.MarkHidden("menu") //nolint:errcheck
137136

138137
return upCmd
139138
}
@@ -167,7 +166,7 @@ func runUp(
167166
ctx context.Context,
168167
dockerCli command.Cli,
169168
backend api.Service,
170-
_ *experimental.State,
169+
experimentals *experimental.State,
171170
createOptions createOptions,
172171
upOptions upOptions,
173172
buildOptions buildOptions,
@@ -187,6 +186,9 @@ func runUp(
187186
if err != nil {
188187
return err
189188
}
189+
if !upOptions.navigationMenuChanged {
190+
upOptions.navigationMenu = SetUnchangedOption(ComposeMenu, experimentals.NavBar())
191+
}
190192

191193
var build *api.BuildOptions
192194
if !createOptions.noBuild {
@@ -259,16 +261,16 @@ func runUp(
259261
return backend.Up(ctx, project, api.UpOptions{
260262
Create: create,
261263
Start: api.StartOptions{
262-
Project: project,
263-
Attach: consumer,
264-
AttachTo: attach,
265-
ExitCodeFrom: upOptions.exitCodeFrom,
266-
CascadeStop: upOptions.cascadeStop,
267-
Wait: upOptions.wait,
268-
WaitTimeout: timeout,
269-
Watch: upOptions.watch,
270-
Services: services,
271-
NavigationBar: upOptions.navigationMenu,
264+
Project: project,
265+
Attach: consumer,
266+
AttachTo: attach,
267+
ExitCodeFrom: upOptions.exitCodeFrom,
268+
CascadeStop: upOptions.cascadeStop,
269+
Wait: upOptions.wait,
270+
WaitTimeout: timeout,
271+
Watch: upOptions.watch,
272+
Services: services,
273+
NavigationMenu: upOptions.navigationMenu,
272274
},
273275
})
274276
}

cmd/formatter/colors.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ var names = []string{
3535
"white",
3636
}
3737

38+
const (
39+
BOLD = "1"
40+
FAINT = "2"
41+
ITALIC = "3"
42+
UNDERLINE = "4"
43+
)
44+
45+
const (
46+
RESET = "0"
47+
CYAN = "36"
48+
)
49+
3850
const (
3951
// Never use ANSI codes
4052
Never = "never"
@@ -72,13 +84,17 @@ var monochrome = func(s string) string {
7284
return s
7385
}
7486

75-
func ansiColor(code, s string) string {
76-
return fmt.Sprintf("%s%s%s", ansiColorCode(code), s, ansiColorCode("0"))
87+
func ansiColor(code, s string, formatOpts ...string) string {
88+
return fmt.Sprintf("%s%s%s", ansiColorCode(code, formatOpts...), s, ansiColorCode("0"))
7789
}
7890

7991
// Everything about ansiColorCode color https://hyperskill.org/learn/step/18193
80-
func ansiColorCode(code string) string {
81-
return fmt.Sprintf("\033[%sm", code)
92+
func ansiColorCode(code string, formatOpts ...string) string {
93+
res := "\033["
94+
for _, c := range formatOpts {
95+
res = fmt.Sprintf("%s%s;", res, c)
96+
}
97+
return fmt.Sprintf("%s%sm", res, code)
8298
}
8399

84100
func makeColorFunc(code string) colorFunc {

cmd/formatter/logs.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,22 @@ func (l *logConsumer) write(w io.Writer, container, message string) {
108108
if l.ctx.Err() != nil {
109109
return
110110
}
111-
print := func() {
111+
printFn := func() {
112112
p := l.getPresenter(container)
113113
timestamp := time.Now().Format(jsonmessage.RFC3339NanoFixed)
114114
for _, line := range strings.Split(message, "\n") {
115+
ClearLine()
115116
if l.timestamp {
116-
fmt.Fprintf(w, "\033[2K%s%s%s\n", p.prefix, timestamp, line)
117+
fmt.Fprintf(w, "%s%s%s\n", p.prefix, timestamp, line)
117118
} else {
118-
fmt.Fprintf(w, "\033[2K%s%s\n", p.prefix, line)
119+
fmt.Fprintf(w, "%s%s\n", p.prefix, line)
119120
}
120121
}
121122
}
122123
if KeyboardManager != nil {
123-
KeyboardManager.PrintKeyboardInfo(print)
124+
KeyboardManager.PrintKeyboardInfo(printFn)
124125
} else {
125-
print()
126+
printFn()
126127
}
127128
}
128129

0 commit comments

Comments
 (0)