Skip to content

Commit 8972e53

Browse files
committed
cli/command: remove prompt utilities that were for internal use
- The `DisableInputEcho` and `PromptForInput` utilities were added in c15ade0 as part of a bug-fix, which was part of v28.x. [There are no (publicly visible) users][1] of either. - The `ErrPromptTerminated` was added in v26.x (originally added in 10bf91a, later updated in commit 7c722c0. [It is not used][2] - The `PromptForConfirmation` was added in [moby@280c872] (docker v1.13.0) as part of the `docker <object> prune` subcommands. It was meant for internal use but exported to allow re-using it in the `container`, `image` (etc.) packages. However, a breaking change to its signature was made in 10bf91a. It currently does [not appear to have any (public) users][2]. This patch removes the `ErrPromptTerminated`, `DisableInputEcho`, `PromptForInput`, and `PromptForConfirmation` utilities from the `cli/command` package. The core functionality of these is still available in the `internal/prompt` package, which we may make public at some point, but still needs some refining / decoupling. [moby@280c872]: moby/moby@280c872 [1]: https://grep.app/search?f.lang=Go&regexp=true&q=%5C.%28DisableInputEcho%7CPromptForInput%29%5C%28 [2]: https://grep.app/search?f.lang=Go&q=%5C.ErrPromptTerminated [3]: https://grep.app/search?f.lang=Go&q=.PromptForConfirmation%28 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent f2c64c1 commit 8972e53

File tree

1 file changed

+0
-39
lines changed

1 file changed

+0
-39
lines changed

cli/command/utils.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,16 @@
44
package command
55

66
import (
7-
"context"
8-
"io"
97
"os"
108
"path/filepath"
119
"strings"
1210

1311
"github.com/docker/cli/cli/config"
14-
"github.com/docker/cli/cli/streams"
15-
"github.com/docker/cli/internal/prompt"
1612
"github.com/moby/moby/api/types/filters"
1713
"github.com/pkg/errors"
1814
"github.com/spf13/pflag"
1915
)
2016

21-
const ErrPromptTerminated = prompt.ErrTerminated
22-
23-
// DisableInputEcho disables input echo on the provided streams.In.
24-
// This is useful when the user provides sensitive information like passwords.
25-
// The function returns a restore function that should be called to restore the
26-
// terminal state.
27-
func DisableInputEcho(ins *streams.In) (restore func() error, err error) {
28-
return prompt.DisableInputEcho(ins)
29-
}
30-
31-
// PromptForInput requests input from the user.
32-
//
33-
// If the user terminates the CLI with SIGINT or SIGTERM while the prompt is
34-
// active, the prompt will return an empty string ("") with an ErrPromptTerminated error.
35-
// When the prompt returns an error, the caller should propagate the error up
36-
// the stack and close the io.Reader used for the prompt which will prevent the
37-
// background goroutine from blocking indefinitely.
38-
func PromptForInput(ctx context.Context, in io.Reader, out io.Writer, message string) (string, error) {
39-
return prompt.ReadInput(ctx, in, out, message)
40-
}
41-
42-
// PromptForConfirmation requests and checks confirmation from the user.
43-
// This will display the provided message followed by ' [y/N] '. If the user
44-
// input 'y' or 'Y' it returns true otherwise false. If no message is provided,
45-
// "Are you sure you want to proceed? [y/N] " will be used instead.
46-
//
47-
// If the user terminates the CLI with SIGINT or SIGTERM while the prompt is
48-
// active, the prompt will return false with an ErrPromptTerminated error.
49-
// When the prompt returns an error, the caller should propagate the error up
50-
// the stack and close the io.Reader used for the prompt which will prevent the
51-
// background goroutine from blocking indefinitely.
52-
func PromptForConfirmation(ctx context.Context, ins io.Reader, outs io.Writer, message string) (bool, error) {
53-
return prompt.Confirm(ctx, ins, outs, message)
54-
}
55-
5617
// PruneFilters merges prune filters specified in config.json with those specified
5718
// as command-line flags.
5819
//

0 commit comments

Comments
 (0)