From bbcad6f572207779ead07127e6619961bc0758b9 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Fri, 31 Aug 2018 09:24:49 +0200 Subject: catch command-not-found errors Add a special handler to catch errors caused by specifying unknown commands to Podman. This allows printing a more helpful error message. ``` $ podman Command "123123" not found. See `podman --help`. $ podman pod 123123 Command "123123" not found. See `podman pod --help`. ``` Signed-off-by: Valentin Rothberg Closes: #1379 Approved by: rhatdan --- cmd/podman/common.go | 4 ++++ cmd/podman/main.go | 1 + 2 files changed, 5 insertions(+) (limited to 'cmd/podman') diff --git a/cmd/podman/common.go b/cmd/podman/common.go index 3d0f1159f..93b16f4e3 100644 --- a/cmd/podman/common.go +++ b/cmd/podman/common.go @@ -51,6 +51,10 @@ func usageErrorHandler(context *cli.Context, err error, _ bool) error { return fmt.Errorf("%s\nSee '%s --help'.", err, cmd) } +func commandNotFoundHandler(context *cli.Context, command string) { + fmt.Fprintf(context.App.Writer, "Command %q not found.\nSee `%s --help`.\n", command, context.App.Name) +} + // validateFlags searches for StringFlags or StringSlice flags that never had // a value set. This commonly occurs when the CLI mistakenly takes the next // option and uses it as a value. diff --git a/cmd/podman/main.go b/cmd/podman/main.go index 24d30fd0e..0e6a2e600 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -52,6 +52,7 @@ func main() { app.Name = "podman" app.Usage = "manage pods and images" app.OnUsageError = usageErrorHandler + app.CommandNotFound = commandNotFoundHandler app.Version = version.Version -- cgit v1.2.3-54-g00ecf