fix: cli prompt termination exit code
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
This commit is contained in:
@ -80,8 +80,10 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
|
||||
// API < v1.42 removes all volumes (anonymous and named) by default.
|
||||
warning = allVolumesWarning
|
||||
}
|
||||
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
||||
return 0, "", errdefs.Cancelled(errors.New("user cancelled operation"))
|
||||
if !options.force {
|
||||
if r, err := command.PromptForConfirmation(ctx, dockerCli.In(), dockerCli.Out(), warning); !r || err != nil {
|
||||
return 0, "", errdefs.Cancelled(errors.New("user cancelled operation"))
|
||||
}
|
||||
}
|
||||
|
||||
report, err := dockerCli.Client().VolumesPrune(ctx, pruneFilters)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package volume
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime"
|
||||
@ -183,3 +184,19 @@ func simplePruneFunc(filters.Args) (types.VolumesPruneReport, error) {
|
||||
SpaceReclaimed: 2000,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestVolumePrunePromptTerminate(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
t.Cleanup(cancel)
|
||||
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
volumePruneFunc: func(filter filters.Args) (types.VolumesPruneReport, error) {
|
||||
return types.VolumesPruneReport{}, errors.New("fakeClient volumePruneFunc should not be called")
|
||||
},
|
||||
})
|
||||
|
||||
cmd := NewPruneCommand(cli)
|
||||
test.TerminatePrompt(ctx, t, cmd, cli, nil)
|
||||
|
||||
golden.Assert(t, cli.OutBuffer().String(), "volume-prune-terminate.golden")
|
||||
}
|
||||
|
||||
2
cli/command/volume/testdata/volume-prune-terminate.golden
vendored
Normal file
2
cli/command/volume/testdata/volume-prune-terminate.golden
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
WARNING! This will remove anonymous local volumes not used by at least one container.
|
||||
Are you sure you want to continue? [y/N]
|
||||
Reference in New Issue
Block a user