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 {
|
if err != nil {
|
||||||
return err
|
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)
|
_, err := s.build(ctx, project, options)
|
||||||
return err
|
return err
|
||||||
}, s.stderr())
|
}, s.stderr(), "Building")
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gocyclo
|
//nolint:gocyclo
|
||||||
|
|
|
@ -44,9 +44,9 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *composeService) Copy(ctx context.Context, projectName string, options api.CopyOptions) error {
|
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)
|
return s.copy(ctx, projectName, options)
|
||||||
}, s.stderr())
|
}, s.stderr(), "Copying")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) copy(ctx context.Context, projectName string, options api.CopyOptions) error {
|
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 {
|
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)
|
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 {
|
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 {
|
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)
|
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 {
|
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 {
|
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)
|
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 {
|
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 {
|
if options.Quiet {
|
||||||
return s.pull(ctx, project, options)
|
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)
|
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
|
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 {
|
if options.Quiet {
|
||||||
return s.push(ctx, project, options)
|
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)
|
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 {
|
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 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)
|
return s.remove(ctx, stoppedContainers, options)
|
||||||
}, s.stderr())
|
}, s.stderr(), "Removing")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) remove(ctx context.Context, containers Containers, options api.RemoveOptions) error {
|
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 {
|
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)
|
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 {
|
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 {
|
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)
|
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 {
|
func (s *composeService) stop(ctx context.Context, projectName string, options api.StopOptions) error {
|
||||||
|
|
|
@ -43,6 +43,7 @@ type ttyWriter struct {
|
||||||
tailEvents []string
|
tailEvents []string
|
||||||
dryRun bool
|
dryRun bool
|
||||||
skipChildEvents bool
|
skipChildEvents bool
|
||||||
|
progressTitle string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *ttyWriter) Start(ctx context.Context) error {
|
func (w *ttyWriter) Start(ctx context.Context) error {
|
||||||
|
@ -149,7 +150,7 @@ func (w *ttyWriter) print() { //nolint:gocyclo
|
||||||
fmt.Fprint(w.out, aec.Hide)
|
fmt.Fprint(w.out, aec.Hide)
|
||||||
defer fmt.Fprint(w.out, aec.Show)
|
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 {
|
if w.numLines != 0 && numDone(w.events) == w.numLines {
|
||||||
firstLine = DoneColor(firstLine)
|
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 {
|
func Run(ctx context.Context, pf progressFunc, out io.Writer) error {
|
||||||
_, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) {
|
_, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) {
|
||||||
return "", pf(ctx)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunWithStatus will run a writer and the progress function in parallel and return a status
|
// 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)
|
eg, _ := errgroup.WithContext(ctx)
|
||||||
w, err := NewWriter(ctx, out)
|
w, err := NewWriter(ctx, out, progressTitle)
|
||||||
var result string
|
var result string
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -105,17 +112,17 @@ const (
|
||||||
var Mode = ModeAuto
|
var Mode = ModeAuto
|
||||||
|
|
||||||
// NewWriter returns a new multi-progress writer
|
// 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)
|
_, isTerminal := term.GetFdInfo(out)
|
||||||
dryRun, ok := ctx.Value(api.DryRunKey{}).(bool)
|
dryRun, ok := ctx.Value(api.DryRunKey{}).(bool)
|
||||||
if !ok {
|
if !ok {
|
||||||
dryRun = false
|
dryRun = false
|
||||||
}
|
}
|
||||||
if Mode == ModeAuto && isTerminal {
|
if Mode == ModeAuto && isTerminal {
|
||||||
return newTTYWriter(out.(console.File), dryRun)
|
return newTTYWriter(out.(console.File), dryRun, progressTitle)
|
||||||
}
|
}
|
||||||
if Mode == ModeTTY {
|
if Mode == ModeTTY {
|
||||||
return newTTYWriter(out.(console.File), dryRun)
|
return newTTYWriter(out.(console.File), dryRun, progressTitle)
|
||||||
}
|
}
|
||||||
return &plainWriter{
|
return &plainWriter{
|
||||||
out: out,
|
out: out,
|
||||||
|
@ -124,19 +131,20 @@ func NewWriter(ctx context.Context, out io.Writer) (Writer, error) {
|
||||||
}, nil
|
}, 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)
|
con, err := console.ConsoleFromFile(out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ttyWriter{
|
return &ttyWriter{
|
||||||
out: con,
|
out: con,
|
||||||
eventIDs: []string{},
|
eventIDs: []string{},
|
||||||
events: map[string]Event{},
|
events: map[string]Event{},
|
||||||
repeated: false,
|
repeated: false,
|
||||||
done: make(chan bool),
|
done: make(chan bool),
|
||||||
mtx: &sync.Mutex{},
|
mtx: &sync.Mutex{},
|
||||||
dryRun: dryRun,
|
dryRun: dryRun,
|
||||||
|
progressTitle: progressTitle,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue