From eb1c79891220fddf4f6036ebcdaf00692f97c13f Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Wed, 8 Feb 2023 22:40:07 +0100 Subject: [PATCH] support dry-run for rm command Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- cmd/compose/remove.go | 1 + pkg/api/api.go | 4 ++-- pkg/api/dryrunclient.go | 2 +- pkg/compose/remove.go | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/compose/remove.go b/cmd/compose/remove.go index 02bb20d8c..50bca5072 100644 --- a/cmd/compose/remove.go +++ b/cmd/compose/remove.go @@ -79,5 +79,6 @@ func runRemove(ctx context.Context, backend api.Service, opts removeOptions, ser Force: opts.force, Volumes: opts.volumes, Project: project, + Stop: opts.stop, }) } diff --git a/pkg/api/api.go b/pkg/api/api.go index 7fedda48b..1f3bd2b5c 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -229,8 +229,8 @@ type KillOptions struct { type RemoveOptions struct { // Project is the compose project used to define this app. Might be nil if user ran command just with project name Project *types.Project - // DryRun just list removable resources - DryRun bool + // Stop option passed in the command line + Stop bool // Volumes remove anonymous volumes Volumes bool // Force don't ask to confirm removal diff --git a/pkg/api/dryrunclient.go b/pkg/api/dryrunclient.go index 9d5ca09dd..e418726f0 100644 --- a/pkg/api/dryrunclient.go +++ b/pkg/api/dryrunclient.go @@ -77,7 +77,7 @@ func (d *DryRunClient) ContainerPause(ctx context.Context, container string) err } func (d *DryRunClient) ContainerRemove(ctx context.Context, container string, options moby.ContainerRemoveOptions) error { - return ErrNotImplemented + return nil } func (d *DryRunClient) ContainerRename(ctx context.Context, container, newContainerName string) error { diff --git a/pkg/compose/remove.go b/pkg/compose/remove.go index 7a5e34d1b..f5eeb829d 100644 --- a/pkg/compose/remove.go +++ b/pkg/compose/remove.go @@ -45,7 +45,7 @@ func (s *composeService) Remove(ctx context.Context, projectName string, options } stoppedContainers := containers.filter(func(c moby.Container) bool { - return c.State != ContainerRunning + return c.State != ContainerRunning || (options.Stop && s.dryRun) }) var names []string