-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add navigation menu with in compose up (attached) #11605
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,20 +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 | ||
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) { | ||
|
@@ -87,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 { | ||
|
@@ -128,6 +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.") | ||
flags.BoolVar(&up.navigationMenu, "menu", false, "Enable interactive shortcuts when running attached (Experimental). Incompatible with --detach.") | ||
flags.MarkHidden("menu") //nolint:errcheck | ||
|
||
return upCmd | ||
} | ||
|
@@ -161,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, | ||
|
@@ -181,6 +186,9 @@ func runUp( | |
if err != nil { | ||
return err | ||
} | ||
if !upOptions.navigationMenuChanged { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems bit complicated to manage value set by env var, is there any drawback doing the same as https://github.com/docker/compose/blob/main/cmd/compose/up.go#L109-L110 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (this comment is mine, I was connected with by @docker.com email while commenting :P) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh indeed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (not for this PR) We definitely need to figure out a re-usable pattern for these types of use cases to simplify driving experimental settings via Docker Desktop and combining with flags/options in Compose Our init sequence has gotten pretty complex between Docker CLI plugin framework + Cobra + Compose itself 😓 |
||
upOptions.navigationMenu = SetUnchangedOption(ComposeMenu, experimentals.NavBar()) | ||
} | ||
|
||
var build *api.BuildOptions | ||
if !createOptions.noBuild { | ||
|
@@ -253,15 +261,16 @@ func runUp( | |
return backend.Up(ctx, project, api.UpOptions{ | ||
Create: create, | ||
Start: api.StartOptions{ | ||
Project: project, | ||
Attach: consumer, | ||
AttachTo: attach, | ||
ExitCodeFrom: upOptions.exitCodeFrom, | ||
CascadeStop: upOptions.cascadeStop, | ||
Wait: upOptions.wait, | ||
WaitTimeout: timeout, | ||
Watch: upOptions.watch, | ||
Services: services, | ||
Project: project, | ||
Attach: consumer, | ||
AttachTo: attach, | ||
ExitCodeFrom: upOptions.exitCodeFrom, | ||
CascadeStop: upOptions.cascadeStop, | ||
Wait: upOptions.wait, | ||
WaitTimeout: timeout, | ||
Watch: upOptions.watch, | ||
Services: services, | ||
NavigationMenu: upOptions.navigationMenu, | ||
}, | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright 2024 Docker Compose CLI authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package formatter | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/acarl005/stripansi" | ||
) | ||
|
||
func ansi(code string) string { | ||
return fmt.Sprintf("\033%s", code) | ||
} | ||
func SaveCursor() { | ||
fmt.Print(ansi("7")) | ||
} | ||
func RestoreCursor() { | ||
fmt.Print(ansi("8")) | ||
} | ||
func HideCursor() { | ||
fmt.Print(ansi("[?25l")) | ||
} | ||
func ShowCursor() { | ||
fmt.Print(ansi("[?25h")) | ||
} | ||
func MoveCursor(y, x int) { | ||
fmt.Print(ansi(fmt.Sprintf("[%d;%dH", y, x))) | ||
} | ||
func MoveCursorX(pos int) { | ||
fmt.Print(ansi(fmt.Sprintf("[%dG", pos))) | ||
} | ||
func ClearLine() { | ||
// Does not move cursor from its current position | ||
fmt.Print(ansi("[2K")) | ||
} | ||
func MoveCursorUp(lines int) { | ||
// Does not add new lines | ||
fmt.Print(ansi(fmt.Sprintf("[%dA", lines))) | ||
} | ||
func MoveCursorDown(lines int) { | ||
// Does not add new lines | ||
fmt.Print(ansi(fmt.Sprintf("[%dB", lines))) | ||
} | ||
func NewLine() { | ||
// Like \n | ||
fmt.Print("\012") | ||
} | ||
func lenAnsi(s string) int { | ||
// len has into consideration ansi codes, if we want | ||
// the len of the actual len(string) we need to strip | ||
// all ansi codes | ||
return len(stripansi.Strip(s)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary for building?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, because by default it should be true, in order not to break tests this is easier to set the COMPOSE_MENU false in all containers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(as a follow-up) We can have the e2e tests set this when they exec Compose to avoid needing it globally like this