Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ const (
ComposeIgnoreOrphans = "COMPOSE_IGNORE_ORPHANS"
// ComposeEnvFiles defines the env files to use if --env-file isn't used
ComposeEnvFiles = "COMPOSE_ENV_FILES"
// ComposeMenu defines if the navigation menu should be rendered. Can be also set via --menu
ComposeMenu = "COMPOSE_MENU"
// ComposeProgress defines type of progress output, if --progress isn't used
ComposeProgress = "COMPOSE_PROGRESS"
)
Expand Down
77 changes: 28 additions & 49 deletions cmd/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (

"github.com/docker/compose/v2/cmd/formatter"
"github.com/docker/compose/v2/pkg/api"
ui "github.com/docker/compose/v2/pkg/progress"
"github.com/docker/compose/v2/pkg/utils"
)

Expand All @@ -44,23 +43,21 @@ type composeOptions struct {

type upOptions struct {
*composeOptions
Detach bool
noStart bool
noDeps bool
cascadeStop bool
cascadeFail 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
Detach bool
noStart bool
noDeps bool
cascadeStop bool
cascadeFail bool
exitCodeFrom string
noColor bool
noPrefix bool
attachDependencies bool
attach []string
noAttach []string
timestamp bool
wait bool
waitTimeout int
watch bool
}

func (opts upOptions) apply(project *types.Project, services []string) (*types.Project, error) {
Expand All @@ -82,22 +79,6 @@ func (opts upOptions) apply(project *types.Project, services []string) (*types.P
return project, nil
}

func (opts *upOptions) validateNavigationMenu(dockerCli command.Cli) {
if !dockerCli.Out().IsTerminal() {
opts.navigationMenu = false
return
}
// If --menu flag was not set
if !opts.navigationMenuChanged {
if envVar, ok := os.LookupEnv(ComposeMenu); ok {
opts.navigationMenu = utils.StringToBool(envVar)
return
}
// ...and COMPOSE_MENU env var is not defined we want the default value to be true
opts.navigationMenu = true
}
}

func (opts upOptions) OnExit() api.Cascade {
switch {
case opts.cascadeStop:
Expand All @@ -119,7 +100,6 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c
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")
if !cmd.Flags().Changed("remove-orphans") {
create.removeOrphans = utils.StringToBool(os.Getenv(ComposeRemoveOrphans))
}
Expand All @@ -134,8 +114,6 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c
return errors.New("cannot combine --attach and --attach-dependencies")
}

up.validateNavigationMenu(dockerCli)

if !p.All && len(project.Services) == 0 {
return fmt.Errorf("no service selected")
}
Expand Down Expand Up @@ -171,7 +149,6 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c
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 in seconds 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. Incompatible with --detach. Can also be enable/disable by setting COMPOSE_MENU environment var.")
flags.BoolVarP(&create.AssumeYes, "yes", "y", false, `Assume "yes" as answer to all prompts and run non-interactively`)
flags.SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {
// assumeYes was introduced by mistake as `--y`
Expand All @@ -181,6 +158,10 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c
}
return pflag.NormalizedName(name)
})

flags.Bool("menu", false, "DISABLED")
_ = flags.MarkHidden("menu")

return upCmd
}

Expand Down Expand Up @@ -223,7 +204,6 @@ func validateFlags(up *upOptions, create *createOptions) error {
return nil
}

//nolint:gocyclo
func runUp(
ctx context.Context,
dockerCli command.Cli,
Expand Down Expand Up @@ -322,16 +302,15 @@ func runUp(
return backend.Up(ctx, project, api.UpOptions{
Create: create,
Start: api.StartOptions{
Project: project,
Attach: consumer,
AttachTo: attach,
ExitCodeFrom: upOptions.exitCodeFrom,
OnExit: upOptions.OnExit(),
Wait: upOptions.wait,
WaitTimeout: timeout,
Watch: upOptions.watch,
Services: services,
NavigationMenu: upOptions.navigationMenu && ui.Mode != "plain" && dockerCli.In().IsTerminal(),
Project: project,
Attach: consumer,
AttachTo: attach,
ExitCodeFrom: upOptions.exitCodeFrom,
OnExit: upOptions.OnExit(),
Wait: upOptions.wait,
WaitTimeout: timeout,
Watch: upOptions.watch,
Services: services,
},
})
}
Expand Down
22 changes: 0 additions & 22 deletions cmd/formatter/ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package formatter

import (
"fmt"

"github.com/acarl005/stripansi"
)

var disableAnsi bool
Expand Down Expand Up @@ -78,30 +76,10 @@ func clearLine() {
fmt.Print(ansi("[2K"))
}

func moveCursorUp(lines int) {
if disableAnsi {
return
}
// Does not add new lines
fmt.Print(ansi(fmt.Sprintf("[%dA", lines)))
}

func moveCursorDown(lines int) {
if disableAnsi {
return
}
// 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))
}
Loading