mirror of https://github.com/docker/compose.git
progress: make title configurable (#10507)
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
parent
2a0e83ad9a
commit
03f4c0e631
|
@ -47,10 +47,10 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
_, err := s.build(ctx, project, options)
|
||||
return err
|
||||
}, s.stderr())
|
||||
}, s.stderr(), "Building")
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
|
|
|
@ -44,9 +44,9 @@ const (
|
|||
)
|
||||
|
||||
func (s *composeService) Copy(ctx context.Context, projectName string, options api.CopyOptions) error {
|
||||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
return s.copy(ctx, projectName, options)
|
||||
}, s.stderr())
|
||||
}, s.stderr(), "Copying")
|
||||
}
|
||||
|
||||
func (s *composeService) copy(ctx context.Context, projectName string, options api.CopyOptions) error {
|
||||
|
|
|
@ -49,9 +49,9 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) Create(ctx context.Context, project *types.Project, options api.CreateOptions) error {
|
||||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
return s.create(ctx, project, options)
|
||||
}, s.stderr())
|
||||
}, s.stderr(), "Creating")
|
||||
}
|
||||
|
||||
func (s *composeService) create(ctx context.Context, project *types.Project, options api.CreateOptions) error {
|
||||
|
|
|
@ -29,9 +29,9 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) Kill(ctx context.Context, projectName string, options api.KillOptions) error {
|
||||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
return s.kill(ctx, strings.ToLower(projectName), options)
|
||||
}, s.stderr())
|
||||
}, s.stderr(), "Killing")
|
||||
}
|
||||
|
||||
func (s *composeService) kill(ctx context.Context, projectName string, options api.KillOptions) error {
|
||||
|
|
|
@ -28,9 +28,9 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) Pause(ctx context.Context, projectName string, options api.PauseOptions) error {
|
||||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
return s.pause(ctx, strings.ToLower(projectName), options)
|
||||
}, s.stderr())
|
||||
}, s.stderr(), "Pausing")
|
||||
}
|
||||
|
||||
func (s *composeService) pause(ctx context.Context, projectName string, options api.PauseOptions) error {
|
||||
|
|
|
@ -42,9 +42,9 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, optio
|
|||
if options.Quiet {
|
||||
return s.pull(ctx, project, options)
|
||||
}
|
||||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
return s.pull(ctx, project, options)
|
||||
}, s.stderr())
|
||||
}, s.stderr(), "Pulling")
|
||||
}
|
||||
|
||||
func (s *composeService) pull(ctx context.Context, project *types.Project, opts api.PullOptions) error { //nolint:gocyclo
|
||||
|
|
|
@ -40,9 +40,9 @@ func (s *composeService) Push(ctx context.Context, project *types.Project, optio
|
|||
if options.Quiet {
|
||||
return s.push(ctx, project, options)
|
||||
}
|
||||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
return s.push(ctx, project, options)
|
||||
}, s.stderr())
|
||||
}, s.stderr(), "Pushing")
|
||||
}
|
||||
|
||||
func (s *composeService) push(ctx context.Context, project *types.Project, options api.PushOptions) error {
|
||||
|
|
|
@ -93,9 +93,9 @@ func (s *composeService) Remove(ctx context.Context, projectName string, options
|
|||
return nil
|
||||
}
|
||||
}
|
||||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
return s.remove(ctx, stoppedContainers, options)
|
||||
}, s.stderr())
|
||||
}, s.stderr(), "Removing")
|
||||
}
|
||||
|
||||
func (s *composeService) remove(ctx context.Context, containers Containers, options api.RemoveOptions) error {
|
||||
|
|
|
@ -29,9 +29,9 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) Restart(ctx context.Context, projectName string, options api.RestartOptions) error {
|
||||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
return s.restart(ctx, strings.ToLower(projectName), options)
|
||||
}, s.stderr())
|
||||
}, s.stderr(), "Restarting")
|
||||
}
|
||||
|
||||
func (s *composeService) restart(ctx context.Context, projectName string, options api.RestartOptions) error {
|
||||
|
|
|
@ -26,9 +26,9 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) Stop(ctx context.Context, projectName string, options api.StopOptions) error {
|
||||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
return s.stop(ctx, strings.ToLower(projectName), options)
|
||||
}, s.stderr())
|
||||
}, s.stderr(), "Stopping")
|
||||
}
|
||||
|
||||
func (s *composeService) stop(ctx context.Context, projectName string, options api.StopOptions) error {
|
||||
|
|
|
@ -43,6 +43,7 @@ type ttyWriter struct {
|
|||
tailEvents []string
|
||||
dryRun bool
|
||||
skipChildEvents bool
|
||||
progressTitle string
|
||||
}
|
||||
|
||||
func (w *ttyWriter) Start(ctx context.Context) error {
|
||||
|
@ -149,7 +150,7 @@ func (w *ttyWriter) print() { //nolint:gocyclo
|
|||
fmt.Fprint(w.out, aec.Hide)
|
||||
defer fmt.Fprint(w.out, aec.Show)
|
||||
|
||||
firstLine := fmt.Sprintf("[+] Running %d/%d", numDone(w.events), w.numLines)
|
||||
firstLine := fmt.Sprintf("[+] %s %d/%d", w.progressTitle, numDone(w.events), w.numLines)
|
||||
if w.numLines != 0 && numDone(w.events) == w.numLines {
|
||||
firstLine = DoneColor(firstLine)
|
||||
}
|
||||
|
|
|
@ -61,14 +61,21 @@ type progressFuncWithStatus func(context.Context) (string, error)
|
|||
func Run(ctx context.Context, pf progressFunc, out io.Writer) error {
|
||||
_, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) {
|
||||
return "", pf(ctx)
|
||||
}, out)
|
||||
}, out, "Running")
|
||||
return err
|
||||
}
|
||||
|
||||
func RunWithTitle(ctx context.Context, pf progressFunc, out io.Writer, progressTitle string) error {
|
||||
_, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) {
|
||||
return "", pf(ctx)
|
||||
}, out, progressTitle)
|
||||
return err
|
||||
}
|
||||
|
||||
// RunWithStatus will run a writer and the progress function in parallel and return a status
|
||||
func RunWithStatus(ctx context.Context, pf progressFuncWithStatus, out io.Writer) (string, error) {
|
||||
func RunWithStatus(ctx context.Context, pf progressFuncWithStatus, out io.Writer, progressTitle string) (string, error) {
|
||||
eg, _ := errgroup.WithContext(ctx)
|
||||
w, err := NewWriter(ctx, out)
|
||||
w, err := NewWriter(ctx, out, progressTitle)
|
||||
var result string
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -105,17 +112,17 @@ const (
|
|||
var Mode = ModeAuto
|
||||
|
||||
// NewWriter returns a new multi-progress writer
|
||||
func NewWriter(ctx context.Context, out io.Writer) (Writer, error) {
|
||||
func NewWriter(ctx context.Context, out io.Writer, progressTitle string) (Writer, error) {
|
||||
_, isTerminal := term.GetFdInfo(out)
|
||||
dryRun, ok := ctx.Value(api.DryRunKey{}).(bool)
|
||||
if !ok {
|
||||
dryRun = false
|
||||
}
|
||||
if Mode == ModeAuto && isTerminal {
|
||||
return newTTYWriter(out.(console.File), dryRun)
|
||||
return newTTYWriter(out.(console.File), dryRun, progressTitle)
|
||||
}
|
||||
if Mode == ModeTTY {
|
||||
return newTTYWriter(out.(console.File), dryRun)
|
||||
return newTTYWriter(out.(console.File), dryRun, progressTitle)
|
||||
}
|
||||
return &plainWriter{
|
||||
out: out,
|
||||
|
@ -124,7 +131,7 @@ func NewWriter(ctx context.Context, out io.Writer) (Writer, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func newTTYWriter(out console.File, dryRun bool) (Writer, error) {
|
||||
func newTTYWriter(out console.File, dryRun bool, progressTitle string) (Writer, error) {
|
||||
con, err := console.ConsoleFromFile(out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -138,5 +145,6 @@ func newTTYWriter(out console.File, dryRun bool) (Writer, error) {
|
|||
done: make(chan bool),
|
||||
mtx: &sync.Mutex{},
|
||||
dryRun: dryRun,
|
||||
progressTitle: progressTitle,
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue