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

Commit 9fd0ac9

Browse files
authored
Merge pull request #1735 from ndeloof/progress_backend
2 parents db30ef7 + 924d792 commit 9fd0ac9

File tree

25 files changed

+142
-138
lines changed

25 files changed

+142
-138
lines changed

aci/compose.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ func (cs *aciComposeService) RunOneOffContainer(ctx context.Context, project *ty
227227
return 0, errdefs.ErrNotImplemented
228228
}
229229

230-
func (cs *aciComposeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) ([]string, error) {
231-
return nil, errdefs.ErrNotImplemented
230+
func (cs *aciComposeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error {
231+
return errdefs.ErrNotImplemented
232232
}
233233

234234
func (cs *aciComposeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) {

api/client/compose.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func (c *composeService) RunOneOffContainer(ctx context.Context, project *types.
8888
return 0, errdefs.ErrNotImplemented
8989
}
9090

91-
func (c *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) ([]string, error) {
92-
return nil, errdefs.ErrNotImplemented
91+
func (c *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error {
92+
return errdefs.ErrNotImplemented
9393
}
9494

9595
func (c *composeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) {

api/compose/api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type Service interface {
5959
// RunOneOffContainer creates a service oneoff container and starts its dependencies
6060
RunOneOffContainer(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
6161
// Remove executes the equivalent to a `compose rm`
62-
Remove(ctx context.Context, project *types.Project, options RemoveOptions) ([]string, error)
62+
Remove(ctx context.Context, project *types.Project, options RemoveOptions) error
6363
// Exec executes a command in a running service container
6464
Exec(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
6565
// Copy copies a file/folder between a service container and the local filesystem
@@ -169,8 +169,9 @@ type PushOptions struct {
169169
IgnoreFailures bool
170170
}
171171

172-
// PullOptions group options of the Push API
172+
// PullOptions group options of the Pull API
173173
type PullOptions struct {
174+
Quiet bool
174175
IgnoreFailures bool
175176
}
176177

api/compose/proxy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type ServiceProxy struct {
4141
ConvertFn func(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error)
4242
KillFn func(ctx context.Context, project *types.Project, options KillOptions) error
4343
RunOneOffContainerFn func(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
44-
RemoveFn func(ctx context.Context, project *types.Project, options RemoveOptions) ([]string, error)
44+
RemoveFn func(ctx context.Context, project *types.Project, options RemoveOptions) error
4545
ExecFn func(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
4646
CopyFn func(ctx context.Context, project *types.Project, opts CopyOptions) error
4747
PauseFn func(ctx context.Context, project string, options PauseOptions) error
@@ -252,9 +252,9 @@ func (s *ServiceProxy) RunOneOffContainer(ctx context.Context, project *types.Pr
252252
}
253253

254254
//Remove implements Service interface
255-
func (s *ServiceProxy) Remove(ctx context.Context, project *types.Project, options RemoveOptions) ([]string, error) {
255+
func (s *ServiceProxy) Remove(ctx context.Context, project *types.Project, options RemoveOptions) error {
256256
if s.RemoveFn == nil {
257-
return nil, errdefs.ErrNotImplemented
257+
return errdefs.ErrNotImplemented
258258
}
259259
for _, i := range s.interceptors {
260260
i(ctx, project)

cli/cmd/compose/build.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/spf13/cobra"
2626

2727
"github.com/docker/compose-cli/api/compose"
28-
"github.com/docker/compose-cli/api/progress"
2928
)
3029

3130
type buildOptions struct {
@@ -88,14 +87,11 @@ func runBuild(ctx context.Context, backend compose.Service, opts buildOptions, s
8887
return err
8988
}
9089

91-
err = progress.Run(ctx, func(ctx context.Context) error {
92-
return backend.Build(ctx, project, compose.BuildOptions{
93-
Pull: opts.pull,
94-
Progress: opts.progress,
95-
Args: types.NewMappingWithEquals(opts.args),
96-
NoCache: opts.noCache,
97-
Quiet: opts.quiet,
98-
})
90+
return backend.Build(ctx, project, compose.BuildOptions{
91+
Pull: opts.pull,
92+
Progress: opts.progress,
93+
Args: types.NewMappingWithEquals(opts.args),
94+
NoCache: opts.noCache,
95+
Quiet: opts.quiet,
9996
})
100-
return err
10197
}

cli/cmd/compose/compose.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ type projectOptions struct {
8787
EnvFile string
8888
}
8989

90+
// ProjectFunc does stuff within a types.Project
91+
type ProjectFunc func(ctx context.Context, project *types.Project) error
92+
93+
// WithServices creates a cobra run command from a ProjectFunc based on configured project options and selected services
94+
func (o *projectOptions) WithServices(services []string, fn ProjectFunc) func(cmd *cobra.Command, args []string) error {
95+
return Adapt(func(ctx context.Context, strings []string) error {
96+
project, err := o.toProject(services)
97+
if err != nil {
98+
return err
99+
}
100+
return fn(ctx, project)
101+
})
102+
}
103+
90104
func (o *projectOptions) addProjectFlags(f *pflag.FlagSet) {
91105
f.StringArrayVar(&o.Profiles, "profile", []string{}, "Specify a profile to enable")
92106
f.StringVarP(&o.ProjectName, "project-name", "p", "", "Project name")

cli/cmd/compose/kill.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,21 @@ package compose
1818

1919
import (
2020
"context"
21+
"os"
2122

23+
"github.com/compose-spec/compose-go/types"
2224
"github.com/spf13/cobra"
2325

2426
"github.com/docker/compose-cli/api/compose"
2527
)
2628

27-
type killOptions struct {
28-
*projectOptions
29-
Signal string
30-
}
31-
3229
func killCommand(p *projectOptions, backend compose.Service) *cobra.Command {
33-
opts := killOptions{
34-
projectOptions: p,
35-
}
30+
var opts compose.KillOptions
3631
cmd := &cobra.Command{
3732
Use: "kill [options] [SERVICE...]",
3833
Short: "Force stop service containers.",
39-
RunE: Adapt(func(ctx context.Context, args []string) error {
40-
return runKill(ctx, backend, opts, args)
34+
RunE: p.WithServices(os.Args, func(ctx context.Context, project *types.Project) error {
35+
return backend.Kill(ctx, project, opts)
4136
}),
4237
}
4338

@@ -46,13 +41,3 @@ func killCommand(p *projectOptions, backend compose.Service) *cobra.Command {
4641

4742
return cmd
4843
}
49-
50-
func runKill(ctx context.Context, backend compose.Service, opts killOptions, services []string) error {
51-
project, err := opts.toProject(services)
52-
if err != nil {
53-
return err
54-
}
55-
return backend.Kill(ctx, project, compose.KillOptions{
56-
Signal: opts.Signal,
57-
})
58-
}

cli/cmd/compose/pause.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/spf13/cobra"
2323

2424
"github.com/docker/compose-cli/api/compose"
25-
"github.com/docker/compose-cli/api/progress"
2625
)
2726

2827
type pauseOptions struct {
@@ -49,12 +48,9 @@ func runPause(ctx context.Context, backend compose.Service, opts pauseOptions, s
4948
return err
5049
}
5150

52-
err = progress.Run(ctx, func(ctx context.Context) error {
53-
return backend.Pause(ctx, project, compose.PauseOptions{
54-
Services: services,
55-
})
51+
return backend.Pause(ctx, project, compose.PauseOptions{
52+
Services: services,
5653
})
57-
return err
5854
}
5955

6056
type unpauseOptions struct {
@@ -81,9 +77,7 @@ func runUnPause(ctx context.Context, backend compose.Service, opts unpauseOption
8177
return err
8278
}
8379

84-
return progress.Run(ctx, func(ctx context.Context) error {
85-
return backend.UnPause(ctx, project, compose.PauseOptions{
86-
Services: services,
87-
})
80+
return backend.UnPause(ctx, project, compose.PauseOptions{
81+
Services: services,
8882
})
8983
}

cli/cmd/compose/pull.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/spf13/cobra"
2626

2727
"github.com/docker/compose-cli/api/compose"
28-
"github.com/docker/compose-cli/api/progress"
2928
"github.com/docker/compose-cli/utils"
3029
)
3130

@@ -86,15 +85,8 @@ func runPull(ctx context.Context, backend compose.Service, opts pullOptions, ser
8685
project.Services = enabled
8786
}
8887

89-
apiOpts := compose.PullOptions{
88+
return backend.Pull(ctx, project, compose.PullOptions{
89+
Quiet: opts.quiet,
9090
IgnoreFailures: opts.ignorePullFailures,
91-
}
92-
93-
if opts.quiet {
94-
return backend.Pull(ctx, project, apiOpts)
95-
}
96-
97-
return progress.Run(ctx, func(ctx context.Context) error {
98-
return backend.Pull(ctx, project, apiOpts)
9991
})
10092
}

cli/cmd/compose/push.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/spf13/cobra"
2323

2424
"github.com/docker/compose-cli/api/compose"
25-
"github.com/docker/compose-cli/api/progress"
2625
)
2726

2827
type pushOptions struct {
@@ -54,9 +53,7 @@ func runPush(ctx context.Context, backend compose.Service, opts pushOptions, ser
5453
return err
5554
}
5655

57-
return progress.Run(ctx, func(ctx context.Context) error {
58-
return backend.Push(ctx, project, compose.PushOptions{
59-
IgnoreFailures: opts.Ignorefailures,
60-
})
56+
return backend.Push(ctx, project, compose.PushOptions{
57+
IgnoreFailures: opts.Ignorefailures,
6158
})
6259
}

0 commit comments

Comments
 (0)