mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
code cleanup: most progress.Run don't return a value
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
89a1a27f80
commit
9b0bc6fee1
@ -50,11 +50,20 @@ func ContextWriter(ctx context.Context) Writer {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
type progressFunc func(context.Context) (string, error)
|
type progressFunc func(context.Context) error
|
||||||
|
|
||||||
// Run will run a writer and the progress function
|
type progressFuncWithStatus func(context.Context) (string, error)
|
||||||
// in parallel
|
|
||||||
func Run(ctx context.Context, pf progressFunc) (string, error) {
|
// Run will run a writer and the progress function in parallel
|
||||||
|
func Run(ctx context.Context, pf progressFunc) error {
|
||||||
|
_, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) {
|
||||||
|
return "", pf(ctx)
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunWithStatus will run a writer and the progress function in parallel and return a status
|
||||||
|
func RunWithStatus(ctx context.Context, pf progressFuncWithStatus) (string, error) {
|
||||||
eg, _ := errgroup.WithContext(ctx)
|
eg, _ := errgroup.WithContext(ctx)
|
||||||
w, err := NewWriter(os.Stderr)
|
w, err := NewWriter(os.Stderr)
|
||||||
var result string
|
var result string
|
||||||
|
@ -88,8 +88,8 @@ func runBuild(ctx context.Context, backend compose.Service, opts buildOptions, s
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
err = progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return "", backend.Build(ctx, project, compose.BuildOptions{
|
return backend.Build(ctx, project, compose.BuildOptions{
|
||||||
Pull: opts.pull,
|
Pull: opts.pull,
|
||||||
Progress: opts.progress,
|
Progress: opts.progress,
|
||||||
Args: types.NewMappingWithEquals(opts.args),
|
Args: types.NewMappingWithEquals(opts.args),
|
||||||
|
@ -73,13 +73,13 @@ func downCommand(p *projectOptions, contextType string, backend compose.Service)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runDown(ctx context.Context, backend compose.Service, opts downOptions) error {
|
func runDown(ctx context.Context, backend compose.Service, opts downOptions) error {
|
||||||
_, err := progress.Run(ctx, func(ctx context.Context) (string, error) {
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
name := opts.ProjectName
|
name := opts.ProjectName
|
||||||
var project *types.Project
|
var project *types.Project
|
||||||
if opts.ProjectName == "" {
|
if opts.ProjectName == "" {
|
||||||
p, err := opts.toProject(nil)
|
p, err := opts.toProject(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
project = p
|
project = p
|
||||||
name = p.Name
|
name = p.Name
|
||||||
@ -90,7 +90,7 @@ func runDown(ctx context.Context, backend compose.Service, opts downOptions) err
|
|||||||
timeoutValue := time.Duration(opts.timeout) * time.Second
|
timeoutValue := time.Duration(opts.timeout) * time.Second
|
||||||
timeout = &timeoutValue
|
timeout = &timeoutValue
|
||||||
}
|
}
|
||||||
return name, backend.Down(ctx, name, compose.DownOptions{
|
return backend.Down(ctx, name, compose.DownOptions{
|
||||||
RemoveOrphans: opts.removeOrphans,
|
RemoveOrphans: opts.removeOrphans,
|
||||||
Project: project,
|
Project: project,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
@ -98,5 +98,4 @@ func runDown(ctx context.Context, backend compose.Service, opts downOptions) err
|
|||||||
Volumes: opts.volumes,
|
Volumes: opts.volumes,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ func runPause(ctx context.Context, backend compose.Service, opts pauseOptions, s
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
err = progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return "", backend.Pause(ctx, project, compose.PauseOptions{
|
return backend.Pause(ctx, project, compose.PauseOptions{
|
||||||
Services: services,
|
Services: services,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -81,10 +81,9 @@ func runUnPause(ctx context.Context, backend compose.Service, opts unpauseOption
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return "", backend.UnPause(ctx, project, compose.PauseOptions{
|
return backend.UnPause(ctx, project, compose.PauseOptions{
|
||||||
Services: services,
|
Services: services,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,7 @@ func runPull(ctx context.Context, backend compose.Service, opts pullOptions, ser
|
|||||||
return backend.Pull(ctx, project, apiOpts)
|
return backend.Pull(ctx, project, apiOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return "", backend.Pull(ctx, project, apiOpts)
|
return backend.Pull(ctx, project, apiOpts)
|
||||||
})
|
})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,9 @@ func runPush(ctx context.Context, backend compose.Service, opts pushOptions, ser
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return "", backend.Push(ctx, project, compose.PushOptions{
|
return backend.Push(ctx, project, compose.PushOptions{
|
||||||
IgnoreFailures: opts.Ignorefailures,
|
IgnoreFailures: opts.Ignorefailures,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
@ -69,18 +69,17 @@ func runRemove(ctx context.Context, backend compose.Service, opts removeOptions,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if opts.stop {
|
if opts.stop {
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
err = progress.Run(ctx, func(ctx context.Context) error {
|
||||||
err := backend.Stop(ctx, project, compose.StopOptions{
|
return backend.Stop(ctx, project, compose.StopOptions{
|
||||||
Services: services,
|
Services: services,
|
||||||
})
|
})
|
||||||
return "", err
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reosurces, err := backend.Remove(ctx, project, compose.RemoveOptions{
|
resources, err := backend.Remove(ctx, project, compose.RemoveOptions{
|
||||||
DryRun: true,
|
DryRun: true,
|
||||||
Services: services,
|
Services: services,
|
||||||
})
|
})
|
||||||
@ -88,11 +87,11 @@ func runRemove(ctx context.Context, backend compose.Service, opts removeOptions,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(reosurces) == 0 {
|
if len(resources) == 0 {
|
||||||
fmt.Println("No stopped containers")
|
fmt.Println("No stopped containers")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
msg := fmt.Sprintf("Going to remove %s", strings.Join(reosurces, ", "))
|
msg := fmt.Sprintf("Going to remove %s", strings.Join(resources, ", "))
|
||||||
if opts.force {
|
if opts.force {
|
||||||
fmt.Println(msg)
|
fmt.Println(msg)
|
||||||
} else {
|
} else {
|
||||||
@ -105,12 +104,11 @@ func runRemove(ctx context.Context, backend compose.Service, opts removeOptions,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
_, err = backend.Remove(ctx, project, compose.RemoveOptions{
|
_, err := backend.Remove(ctx, project, compose.RemoveOptions{
|
||||||
Volumes: opts.volumes,
|
Volumes: opts.volumes,
|
||||||
Force: opts.force,
|
Force: opts.force,
|
||||||
})
|
})
|
||||||
return "", err
|
return err
|
||||||
})
|
})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
@ -55,11 +55,10 @@ func runRestart(ctx context.Context, backend compose.Service, opts restartOption
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeout := time.Duration(opts.timeout) * time.Second
|
timeout := time.Duration(opts.timeout) * time.Second
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return "", backend.Restart(ctx, project, compose.RestartOptions{
|
return backend.Restart(ctx, project, compose.RestartOptions{
|
||||||
Timeout: &timeout,
|
Timeout: &timeout,
|
||||||
Services: services,
|
Services: services,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
@ -154,8 +154,8 @@ func runRun(ctx context.Context, backend compose.Service, opts runOptions) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
err = progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return "", startDependencies(ctx, backend, *project, opts.Service)
|
return startDependencies(ctx, backend, *project, opts.Service)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -49,8 +49,7 @@ func runStart(ctx context.Context, backend compose.Service, opts startOptions, s
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return "", backend.Start(ctx, project, compose.StartOptions{})
|
return backend.Start(ctx, project, compose.StartOptions{})
|
||||||
})
|
})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
@ -63,11 +63,10 @@ func runStop(ctx context.Context, backend compose.Service, opts stopOptions, ser
|
|||||||
timeoutValue := time.Duration(opts.timeout) * time.Second
|
timeoutValue := time.Duration(opts.timeout) * time.Second
|
||||||
timeout = &timeoutValue
|
timeout = &timeoutValue
|
||||||
}
|
}
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return "", backend.Stop(ctx, project, compose.StopOptions{
|
return backend.Stop(ctx, project, compose.StopOptions{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
Services: services,
|
Services: services,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
@ -214,13 +214,12 @@ func runUp(ctx context.Context, backend compose.Service, opts upOptions, service
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return "", backend.Up(ctx, project, compose.UpOptions{
|
return backend.Up(ctx, project, compose.UpOptions{
|
||||||
Detach: opts.Detach,
|
Detach: opts.Detach,
|
||||||
QuietPull: opts.quietPull,
|
QuietPull: opts.quietPull,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCreateStart(ctx context.Context, backend compose.Service, opts upOptions, services []string) error {
|
func runCreateStart(ctx context.Context, backend compose.Service, opts upOptions, services []string) error {
|
||||||
@ -238,7 +237,7 @@ func runCreateStart(ctx context.Context, backend compose.Service, opts upOptions
|
|||||||
return fmt.Errorf("no service selected")
|
return fmt.Errorf("no service selected")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
err = progress.Run(ctx, func(ctx context.Context) error {
|
||||||
err := backend.Create(ctx, project, compose.CreateOptions{
|
err := backend.Create(ctx, project, compose.CreateOptions{
|
||||||
Services: services,
|
Services: services,
|
||||||
RemoveOrphans: opts.removeOrphans,
|
RemoveOrphans: opts.removeOrphans,
|
||||||
@ -249,14 +248,14 @@ func runCreateStart(ctx context.Context, backend compose.Service, opts upOptions
|
|||||||
QuietPull: opts.quietPull,
|
QuietPull: opts.quietPull,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
if opts.Detach {
|
if opts.Detach {
|
||||||
err = backend.Start(ctx, project, compose.StartOptions{
|
err = backend.Start(ctx, project, compose.StartOptions{
|
||||||
Services: services,
|
Services: services,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return "", err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -282,15 +281,14 @@ func runCreateStart(ctx context.Context, backend compose.Service, opts upOptions
|
|||||||
|
|
||||||
stopFunc := func() error {
|
stopFunc := func() error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, err := progress.Run(ctx, func(ctx context.Context) (string, error) {
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
go func() {
|
go func() {
|
||||||
<-signalChan
|
<-signalChan
|
||||||
backend.Kill(ctx, project, compose.KillOptions{}) // nolint:errcheck
|
backend.Kill(ctx, project, compose.KillOptions{}) // nolint:errcheck
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return "", backend.Stop(ctx, project, compose.StopOptions{})
|
return backend.Stop(ctx, project, compose.StopOptions{})
|
||||||
})
|
})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
<-signalChan
|
<-signalChan
|
||||||
|
@ -103,7 +103,7 @@ func runRun(ctx context.Context, image string, contextType string, opts run.Opts
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := progress.Run(ctx, func(ctx context.Context) (string, error) {
|
result, err := progress.RunWithStatus(ctx, func(ctx context.Context) (string, error) {
|
||||||
return containerConfig.ID, c.ContainerService().Run(ctx, containerConfig)
|
return containerConfig.ID, c.ContainerService().Run(ctx, containerConfig)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -74,7 +74,7 @@ func createVolume(ctype string) *cobra.Command {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
result, err := progress.Run(ctx, func(ctx context.Context) (string, error) {
|
result, err := progress.RunWithStatus(ctx, func(ctx context.Context) (string, error) {
|
||||||
volume, err := c.VolumeService().Create(ctx, args[0], opts)
|
volume, err := c.VolumeService().Create(ctx, args[0], opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user