mirror of
https://github.com/docker/compose.git
synced 2025-07-22 13:14:29 +02:00
Merge pull request #9247 from ndeloof/plain
use plain text progress when ansi=never is set
This commit is contained in:
commit
ce944520ff
@ -29,16 +29,17 @@ import (
|
|||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
dockercli "github.com/docker/cli/cli"
|
dockercli "github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli-plugins/manager"
|
"github.com/docker/cli/cli-plugins/manager"
|
||||||
"github.com/docker/compose/v2/cmd/formatter"
|
|
||||||
"github.com/docker/compose/v2/pkg/utils"
|
|
||||||
"github.com/morikuni/aec"
|
"github.com/morikuni/aec"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
|
"github.com/docker/compose/v2/cmd/formatter"
|
||||||
"github.com/docker/compose/v2/pkg/api"
|
"github.com/docker/compose/v2/pkg/api"
|
||||||
"github.com/docker/compose/v2/pkg/compose"
|
"github.com/docker/compose/v2/pkg/compose"
|
||||||
|
"github.com/docker/compose/v2/pkg/progress"
|
||||||
|
"github.com/docker/compose/v2/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command defines a compose CLI command as a func with args
|
// Command defines a compose CLI command as a func with args
|
||||||
@ -271,6 +272,12 @@ func RootCommand(backend api.Service) *cobra.Command {
|
|||||||
logrus.SetLevel(logrus.TraceLevel)
|
logrus.SetLevel(logrus.TraceLevel)
|
||||||
}
|
}
|
||||||
formatter.SetANSIMode(ansi)
|
formatter.SetANSIMode(ansi)
|
||||||
|
switch ansi {
|
||||||
|
case "never":
|
||||||
|
progress.Mode = progress.ModePlain
|
||||||
|
case "tty":
|
||||||
|
progress.Mode = progress.ModeTTY
|
||||||
|
}
|
||||||
if opts.WorkDir != "" {
|
if opts.WorkDir != "" {
|
||||||
if opts.ProjectDir != "" {
|
if opts.ProjectDir != "" {
|
||||||
return errors.New(`cannot specify DEPRECATED "--workdir" and "--project-directory". Please use only "--project-directory" instead`)
|
return errors.New(`cannot specify DEPRECATED "--workdir" and "--project-directory". Please use only "--project-directory" instead`)
|
||||||
|
@ -90,11 +90,34 @@ func RunWithStatus(ctx context.Context, pf progressFuncWithStatus) (string, erro
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ModeAuto detect console capabilities
|
||||||
|
ModeAuto = "auto"
|
||||||
|
// ModeTTY use terminal capability for advanced rendering
|
||||||
|
ModeTTY = "tty"
|
||||||
|
// ModePlain dump raw events to output
|
||||||
|
ModePlain = "plain"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Mode define how progress should be rendered, either as ModePlain or ModeTTY
|
||||||
|
var Mode = ModeAuto
|
||||||
|
|
||||||
// NewWriter returns a new multi-progress writer
|
// NewWriter returns a new multi-progress writer
|
||||||
func NewWriter(out console.File) (Writer, error) {
|
func NewWriter(out console.File) (Writer, error) {
|
||||||
_, isTerminal := term.GetFdInfo(out)
|
_, isTerminal := term.GetFdInfo(out)
|
||||||
|
if Mode == ModeAuto && isTerminal {
|
||||||
|
return newTTYWriter(out)
|
||||||
|
}
|
||||||
|
if Mode == ModeTTY {
|
||||||
|
return newTTYWriter(out)
|
||||||
|
}
|
||||||
|
return &plainWriter{
|
||||||
|
out: out,
|
||||||
|
done: make(chan bool),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
if isTerminal {
|
func newTTYWriter(out console.File) (Writer, error) {
|
||||||
con, err := console.ConsoleFromFile(out)
|
con, err := console.ConsoleFromFile(out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -108,10 +131,4 @@ func NewWriter(out console.File) (Writer, error) {
|
|||||||
done: make(chan bool),
|
done: make(chan bool),
|
||||||
mtx: &sync.Mutex{},
|
mtx: &sync.Mutex{},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
|
||||||
|
|
||||||
return &plainWriter{
|
|
||||||
out: out,
|
|
||||||
done: make(chan bool),
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user