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 <vrothberg@suse.com>

Closes: #1379
Approved by: rhatdan
This commit is contained in:
Valentin Rothberg
2018-08-31 09:24:49 +02:00
committed by Atomic Bot
parent 3839c00ae2
commit bbcad6f572
2 changed files with 5 additions and 0 deletions

View File

@@ -51,6 +51,10 @@ func usageErrorHandler(context *cli.Context, err error, _ bool) error {
return fmt.Errorf("%s\nSee '%s --help'.", err, cmd) 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 // validateFlags searches for StringFlags or StringSlice flags that never had
// a value set. This commonly occurs when the CLI mistakenly takes the next // a value set. This commonly occurs when the CLI mistakenly takes the next
// option and uses it as a value. // option and uses it as a value.

View File

@@ -52,6 +52,7 @@ func main() {
app.Name = "podman" app.Name = "podman"
app.Usage = "manage pods and images" app.Usage = "manage pods and images"
app.OnUsageError = usageErrorHandler app.OnUsageError = usageErrorHandler
app.CommandNotFound = commandNotFoundHandler
app.Version = version.Version app.Version = version.Version