Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 3ec33fa

Browse files
authored
Merge pull request #1730 from ndeloof/progress_cleanup
code cleanup: most progress.Run don't return a value
2 parents 907e8e1 + 9b0bc6f commit 3ec33fa

File tree

14 files changed

+51
-53
lines changed

14 files changed

+51
-53
lines changed

api/progress/writer.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@ func ContextWriter(ctx context.Context) Writer {
5050
return s
5151
}
5252

53-
type progressFunc func(context.Context) (string, error)
53+
type progressFunc func(context.Context) error
5454

55-
// Run will run a writer and the progress function
56-
// in parallel
57-
func Run(ctx context.Context, pf progressFunc) (string, error) {
55+
type progressFuncWithStatus func(context.Context) (string, error)
56+
57+
// Run will run a writer and the progress function in parallel
58+
func Run(ctx context.Context, pf progressFunc) error {
59+
_, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) {
60+
return "", pf(ctx)
61+
})
62+
return err
63+
}
64+
65+
// RunWithStatus will run a writer and the progress function in parallel and return a status
66+
func RunWithStatus(ctx context.Context, pf progressFuncWithStatus) (string, error) {
5867
eg, _ := errgroup.WithContext(ctx)
5968
w, err := NewWriter(os.Stderr)
6069
var result string

cli/cmd/compose/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func runBuild(ctx context.Context, backend compose.Service, opts buildOptions, s
8888
return err
8989
}
9090

91-
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
92-
return "", backend.Build(ctx, project, compose.BuildOptions{
91+
err = progress.Run(ctx, func(ctx context.Context) error {
92+
return backend.Build(ctx, project, compose.BuildOptions{
9393
Pull: opts.pull,
9494
Progress: opts.progress,
9595
Args: types.NewMappingWithEquals(opts.args),

cli/cmd/compose/down.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ func downCommand(p *projectOptions, contextType string, backend compose.Service)
7373
}
7474

7575
func runDown(ctx context.Context, backend compose.Service, opts downOptions) error {
76-
_, err := progress.Run(ctx, func(ctx context.Context) (string, error) {
76+
return progress.Run(ctx, func(ctx context.Context) error {
7777
name := opts.ProjectName
7878
var project *types.Project
7979
if opts.ProjectName == "" {
8080
p, err := opts.toProject(nil)
8181
if err != nil {
82-
return "", err
82+
return err
8383
}
8484
project = p
8585
name = p.Name
@@ -90,13 +90,12 @@ func runDown(ctx context.Context, backend compose.Service, opts downOptions) err
9090
timeoutValue := time.Duration(opts.timeout) * time.Second
9191
timeout = &timeoutValue
9292
}
93-
return name, backend.Down(ctx, name, compose.DownOptions{
93+
return backend.Down(ctx, name, compose.DownOptions{
9494
RemoveOrphans: opts.removeOrphans,
9595
Project: project,
9696
Timeout: timeout,
9797
Images: opts.images,
9898
Volumes: opts.volumes,
9999
})
100100
})
101-
return err
102101
}

cli/cmd/compose/pause.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func runPause(ctx context.Context, backend compose.Service, opts pauseOptions, s
4949
return err
5050
}
5151

52-
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
53-
return "", backend.Pause(ctx, project, compose.PauseOptions{
52+
err = progress.Run(ctx, func(ctx context.Context) error {
53+
return backend.Pause(ctx, project, compose.PauseOptions{
5454
Services: services,
5555
})
5656
})
@@ -81,10 +81,9 @@ func runUnPause(ctx context.Context, backend compose.Service, opts unpauseOption
8181
return err
8282
}
8383

84-
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
85-
return "", backend.UnPause(ctx, project, compose.PauseOptions{
84+
return progress.Run(ctx, func(ctx context.Context) error {
85+
return backend.UnPause(ctx, project, compose.PauseOptions{
8686
Services: services,
8787
})
8888
})
89-
return err
9089
}

cli/cmd/compose/pull.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ func runPull(ctx context.Context, backend compose.Service, opts pullOptions, ser
9494
return backend.Pull(ctx, project, apiOpts)
9595
}
9696

97-
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
98-
return "", backend.Pull(ctx, project, apiOpts)
97+
return progress.Run(ctx, func(ctx context.Context) error {
98+
return backend.Pull(ctx, project, apiOpts)
9999
})
100-
return err
101100
}

cli/cmd/compose/push.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ func runPush(ctx context.Context, backend compose.Service, opts pushOptions, ser
5454
return err
5555
}
5656

57-
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
58-
return "", backend.Push(ctx, project, compose.PushOptions{
57+
return progress.Run(ctx, func(ctx context.Context) error {
58+
return backend.Push(ctx, project, compose.PushOptions{
5959
IgnoreFailures: opts.Ignorefailures,
6060
})
6161
})
62-
return err
6362
}

cli/cmd/compose/remove.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,29 @@ func runRemove(ctx context.Context, backend compose.Service, opts removeOptions,
6969
}
7070

7171
if opts.stop {
72-
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
73-
err := backend.Stop(ctx, project, compose.StopOptions{
72+
err = progress.Run(ctx, func(ctx context.Context) error {
73+
return backend.Stop(ctx, project, compose.StopOptions{
7474
Services: services,
7575
})
76-
return "", err
7776
})
7877
if err != nil {
7978
return err
8079
}
8180
}
8281

83-
reosurces, err := backend.Remove(ctx, project, compose.RemoveOptions{
82+
resources, err := backend.Remove(ctx, project, compose.RemoveOptions{
8483
DryRun: true,
8584
Services: services,
8685
})
8786
if err != nil {
8887
return err
8988
}
9089

91-
if len(reosurces) == 0 {
90+
if len(resources) == 0 {
9291
fmt.Println("No stopped containers")
9392
return nil
9493
}
95-
msg := fmt.Sprintf("Going to remove %s", strings.Join(reosurces, ", "))
94+
msg := fmt.Sprintf("Going to remove %s", strings.Join(resources, ", "))
9695
if opts.force {
9796
fmt.Println(msg)
9897
} else {
@@ -105,12 +104,11 @@ func runRemove(ctx context.Context, backend compose.Service, opts removeOptions,
105104
}
106105
}
107106

108-
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
109-
_, err = backend.Remove(ctx, project, compose.RemoveOptions{
107+
return progress.Run(ctx, func(ctx context.Context) error {
108+
_, err := backend.Remove(ctx, project, compose.RemoveOptions{
110109
Volumes: opts.volumes,
111110
Force: opts.force,
112111
})
113-
return "", err
112+
return err
114113
})
115-
return err
116114
}

cli/cmd/compose/restart.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ func runRestart(ctx context.Context, backend compose.Service, opts restartOption
5555
}
5656

5757
timeout := time.Duration(opts.timeout) * time.Second
58-
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
59-
return "", backend.Restart(ctx, project, compose.RestartOptions{
58+
return progress.Run(ctx, func(ctx context.Context) error {
59+
return backend.Restart(ctx, project, compose.RestartOptions{
6060
Timeout: &timeout,
6161
Services: services,
6262
})
6363
})
64-
return err
6564
}

cli/cmd/compose/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ func runRun(ctx context.Context, backend compose.Service, opts runOptions) error
154154
return err
155155
}
156156

157-
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
158-
return "", startDependencies(ctx, backend, *project, opts.Service)
157+
err = progress.Run(ctx, func(ctx context.Context) error {
158+
return startDependencies(ctx, backend, *project, opts.Service)
159159
})
160160
if err != nil {
161161
return err

cli/cmd/compose/start.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ func runStart(ctx context.Context, backend compose.Service, opts startOptions, s
4949
return err
5050
}
5151

52-
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
53-
return "", backend.Start(ctx, project, compose.StartOptions{})
52+
return progress.Run(ctx, func(ctx context.Context) error {
53+
return backend.Start(ctx, project, compose.StartOptions{})
5454
})
55-
return err
5655
}

0 commit comments

Comments
 (0)