Skip to content

refactor(up): inject the navigation menu instead of importing cmd/formatter - #14324

Merged
glours merged 3 commits into
docker:mainfrom
ndeloof:refactor/navigation-menu-inversion
Oct 12, 2026
Merged

glours merged 3 commits into
docker:mainfrom
ndeloof:refactor/navigation-menu-inversion

Conversation

@ndeloof

@ndeloof ndeloof commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does, in one sentence

Stops the Compose library (pkg/compose) from importing the CLI's terminal code: the interactive menu of compose up becomes an interface the library drives and the CLI injects.

Context

pkg/compose imported cmd/formatter to build the keyboard menu shown during a foreground compose up. So the SDK depended on the CLI package, and nothing prevented more such imports from creeping in. The menu is terminal rendering, so it belongs with the CLI, but the library has to drive it during up.

What the PR brings

  • A NavigationMenu interface and a factory in pkg/compose, implemented by formatter.LogKeyboard, and a WithNavigationMenu option on NewComposeService. cmd/main.go injects the formatter implementation, so the terminal code stays in cmd/formatter and compose up behaves exactly as before.
  • pkg/compose and internal/ no longer import cmd/, and a lint rule keeps it that way.
  • SDK callers who set NavigationMenu: true must now provide an implementation through the option; without it no menu is displayed and a warning says so.

The injected menu also owns the terminal: it grabs the keyboard, reads the keys and gives the terminal back, so the library neither imports the keyboard library nor sees raw key events. The interface is just what up needs from a menu: decorate the logs, enable watch and detach, then run until the session ends.

🤖 Generated with Claude Code

…matter

pkg/compose imported cmd/formatter for the interactive keyboard menu of a
foreground up, so the library depended on the CLI. Define a NavigationMenu
interface (and a factory) in pkg/compose, satisfied by formatter.LogKeyboard,
and have the CLI inject it with the new WithNavigationMenu option. The terminal
code stays in cmd/formatter. Without the option no menu is displayed.

formatter.Feature moves to api.Feature so that both sides share the type, and
a depguard rule now forbids pkg/ and internal/ from importing cmd/.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof requested review from a team as code owners October 10, 2026 12:13

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟡 NEEDS ATTENTION

Comment thread pkg/compose/navigation_menu.go Outdated

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟡 NEEDS ATTENTION

1 medium-severity finding in the new navigation menu injection introduced by this PR.

Comment thread pkg/compose/up.go
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.28571% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/compose/up.go 65.38% 7 Missing and 2 partials ⚠️
cmd/formatter/shortcut.go 65.21% 8 Missing ⚠️
cmd/main.go 0.00% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

pkg/compose still imported the keyboard library: it grabbed the terminal,
forwarded raw key events to the menu and released the terminal on exit.

The NavigationMenu now takes care of all of it through Open, Run and Close,
so the library no longer knows about keys or the terminal, and the menu
interface no longer exposes a third-party event type.

As a side effect, key handling no longer shares a goroutine with the
signal handling loop of `up`.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof requested a review from docker-agent October 10, 2026 16:26

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review covers only the commits pushed since f66220634a42 (the navigation-menu inversion base); earlier commits were already reviewed.

Assessment: 🟡 NEEDS ATTENTION

Two moderate-confidence findings in the new Open/Run/Close keyboard lifecycle added to cmd/formatter/shortcut.go. Both are conditional on unverifiable eiannone/keyboard library behaviour (the module source is not in the local cache), but the defensive fixes cost nothing and make the documented intent code-level explicit.

Comment thread cmd/formatter/shortcut.go Outdated
Comment thread cmd/formatter/shortcut.go
keyboard.Close closes the channel handed out by GetKeys. Run kept reading
zero-value events from it until its context was done.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof requested a review from docker-agent October 10, 2026 16:40

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review covers only the commits pushed since 51c8bbaa5f0c.

Assessment: 🟢 APPROVE

The single change in this incremental diff — switching the channel receive in Run() to the two-return form and returning when ok is false — is the correct, idiomatic Go fix for the closed-channel spin loop identified in the prior review. No new issues introduced.

@glours glours left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glours
glours merged commit 7a34cdb into docker:main Oct 12, 2026
65 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants