don't print help message for usage errors

Don't print potentially verbose help messages in case of usage errors,
but print only the usage error followed by a pointer to the command's
help.  This aligns with Docker.

```
$ podman run -h
flag needs an argument: -h
See 'podman run --help'.
```

Signed-off-by: Valentin Rothberg <vrothberg@suse.com>

Closes: #1379
Approved by: rhatdan
This commit is contained in:
Valentin Rothberg
2018-08-30 19:31:05 +02:00
committed by Atomic Bot
parent 82a6b373a5
commit 3839c00ae2
57 changed files with 216 additions and 148 deletions

View File

@@ -27,12 +27,13 @@ var (
}
attachDescription = "The podman attach command allows you to attach to a running container using the container's ID or name, either to view its ongoing output or to control it interactively."
attachCommand = cli.Command{
Name: "attach",
Usage: "Attach to a running container",
Description: attachDescription,
Flags: attachFlags,
Action: attachCmd,
ArgsUsage: "",
Name: "attach",
Usage: "Attach to a running container",
Description: attachDescription,
Flags: attachFlags,
Action: attachCmd,
ArgsUsage: "",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -28,6 +28,7 @@ var (
Action: buildCmd,
ArgsUsage: "CONTEXT-DIRECTORY | URL",
SkipArgReorder: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -24,12 +24,13 @@ var (
Cleans up mount points and network stacks on one or more containers from the host. The container name or ID can be used. This command is used internally when running containers, but can also be used if container cleanup has failed when a container exits.
`
cleanupCommand = cli.Command{
Name: "cleanup",
Usage: "Cleanup network and mountpoints of one or more containers",
Description: cleanupDescription,
Flags: cleanupFlags,
Action: cleanupCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
Name: "cleanup",
Usage: "Cleanup network and mountpoints of one or more containers",
Description: cleanupDescription,
Flags: cleanupFlags,
Action: cleanupCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -49,12 +49,13 @@ var (
set the commit message with the --message flag,
and make changes to the instructions with the --change flag.`
commitCommand = cli.Command{
Name: "commit",
Usage: "Create new image based on the changed container",
Description: commitDescription,
Flags: commitFlags,
Action: commitCmd,
ArgsUsage: "CONTAINER [REPOSITORY[:TAG]]",
Name: "commit",
Usage: "Create new image based on the changed container",
Description: commitDescription,
Flags: commitFlags,
Action: commitCmd,
ArgsUsage: "CONTAINER [REPOSITORY[:TAG]]",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"reflect"
"regexp"
"strings"
@@ -42,6 +43,14 @@ func shortID(id string) string {
return id
}
func usageErrorHandler(context *cli.Context, err error, _ bool) error {
cmd := context.App.Name
if len(context.Command.Name) > 0 {
cmd = cmd + " " + context.Command.Name
}
return fmt.Errorf("%s\nSee '%s --help'.", err, cmd)
}
// 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.

View File

@@ -43,5 +43,6 @@ var (
ArgsUsage: "",
Subcommands: subCommands,
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -52,6 +52,7 @@ var createCommand = cli.Command{
HideHelp: true,
SkipArgReorder: true,
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
func createCmd(c *cli.Context) error {

View File

@@ -48,12 +48,13 @@ var (
container or image will be compared to its parent layer`)
diffCommand = cli.Command{
Name: "diff",
Usage: "Inspect changes on container's file systems",
Description: diffDescription,
Flags: diffFlags,
Action: diffCmd,
ArgsUsage: "ID-NAME",
Name: "diff",
Usage: "Inspect changes on container's file systems",
Description: diffDescription,
Flags: diffFlags,
Action: diffCmd,
ArgsUsage: "ID-NAME",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -51,6 +51,7 @@ var (
ArgsUsage: "CONTAINER-NAME",
SkipArgReorder: true,
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -20,12 +20,13 @@ var (
exportDescription = "Exports container's filesystem contents as a tar archive" +
" and saves it on the local machine."
exportCommand = cli.Command{
Name: "export",
Usage: "Export container's filesystem contents as a tar archive",
Description: exportDescription,
Flags: exportFlags,
Action: exportCmd,
ArgsUsage: "CONTAINER",
Name: "export",
Usage: "Export container's filesystem contents as a tar archive",
Description: exportDescription,
Flags: exportFlags,
Action: exportCmd,
ArgsUsage: "CONTAINER",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -63,6 +63,7 @@ var (
Action: historyCmd,
ArgsUsage: "",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -28,5 +28,6 @@ var (
ArgsUsage: "",
Subcommands: imageSubCommands,
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -128,6 +128,7 @@ var (
Action: imagesCmd,
ArgsUsage: "",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
lsImagesCommand = cli.Command{
Name: "ls",
@@ -137,6 +138,7 @@ var (
Action: imagesCmd,
ArgsUsage: "",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -36,12 +36,13 @@ var (
Optionally tag the image. You can specify the instructions using the --change option.
`
importCommand = cli.Command{
Name: "import",
Usage: "Import a tarball to create a filesystem image",
Description: importDescription,
Flags: importFlags,
Action: importCmd,
ArgsUsage: "TARBALL [REFERENCE]",
Name: "import",
Usage: "Import a tarball to create a filesystem image",
Description: importDescription,
Flags: importFlags,
Action: importCmd,
ArgsUsage: "TARBALL [REFERENCE]",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -13,12 +13,13 @@ import (
var (
infoDescription = "Display podman system information"
infoCommand = cli.Command{
Name: "info",
Usage: infoDescription,
Description: `Information display here pertain to the host, current storage stats, and build of podman. Useful for the user and when reporting issues.`,
Flags: infoFlags,
Action: infoCmd,
ArgsUsage: "",
Name: "info",
Usage: infoDescription,
Description: `Information display here pertain to the host, current storage stats, and build of podman. Useful for the user and when reporting issues.`,
Flags: infoFlags,
Action: infoCmd,
ArgsUsage: "",
OnUsageError: usageErrorHandler,
}
infoFlags = []cli.Flag{
cli.BoolFlag{

View File

@@ -38,12 +38,13 @@ var (
}
inspectDescription = "This displays the low-level information on containers and images identified by name or ID. By default, this will render all results in a JSON array. If the container and image have the same name, this will return container JSON for unspecified type."
inspectCommand = cli.Command{
Name: "inspect",
Usage: "Displays the configuration of a container or image",
Description: inspectDescription,
Flags: inspectFlags,
Action: inspectCmd,
ArgsUsage: "CONTAINER-OR-IMAGE [CONTAINER-OR-IMAGE]...",
Name: "inspect",
Usage: "Displays the configuration of a container or image",
Description: inspectDescription,
Flags: inspectFlags,
Action: inspectCmd,
ArgsUsage: "CONTAINER-OR-IMAGE [CONTAINER-OR-IMAGE]...",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -30,6 +30,7 @@ var (
Action: killCmd,
ArgsUsage: "[CONTAINER_NAME_OR_ID]",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -33,12 +33,13 @@ var (
}
loadDescription = "Loads the image from docker-archive stored on the local machine."
loadCommand = cli.Command{
Name: "load",
Usage: "Load an image from docker archive",
Description: loadDescription,
Flags: loadFlags,
Action: loadCmd,
ArgsUsage: "",
Name: "load",
Usage: "Load an image from docker archive",
Description: loadDescription,
Flags: loadFlags,
Action: loadCmd,
ArgsUsage: "",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -40,12 +40,13 @@ var (
}
loginDescription = "Login to a container registry on a specified server."
loginCommand = cli.Command{
Name: "login",
Usage: "Login to a container registry",
Description: loginDescription,
Flags: loginFlags,
Action: loginCmd,
ArgsUsage: "REGISTRY",
Name: "login",
Usage: "Login to a container registry",
Description: loginDescription,
Flags: loginFlags,
Action: loginCmd,
ArgsUsage: "REGISTRY",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -22,12 +22,13 @@ var (
}
logoutDescription = "Remove the cached username and password for the registry."
logoutCommand = cli.Command{
Name: "logout",
Usage: "Logout of a container registry",
Description: logoutDescription,
Flags: logoutFlags,
Action: logoutCmd,
ArgsUsage: "REGISTRY",
Name: "logout",
Usage: "Logout of a container registry",
Description: logoutDescription,
Flags: logoutFlags,
Action: logoutCmd,
ArgsUsage: "REGISTRY",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -58,6 +58,7 @@ var (
Action: logsCmd,
ArgsUsage: "CONTAINER",
SkipArgReorder: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -51,6 +51,7 @@ func main() {
app := cli.NewApp()
app.Name = "podman"
app.Usage = "manage pods and images"
app.OnUsageError = usageErrorHandler
app.Version = version.Version

View File

@@ -31,12 +31,13 @@ var (
},
}
mountCommand = cli.Command{
Name: "mount",
Usage: "Mount a working container's root filesystem",
Description: mountDescription,
Action: mountCmd,
ArgsUsage: "[CONTAINER-NAME-OR-ID [...]]",
Flags: mountFlags,
Name: "mount",
Usage: "Mount a working container's root filesystem",
Description: mountDescription,
Action: mountCmd,
ArgsUsage: "[CONTAINER-NAME-OR-ID [...]]",
Flags: mountFlags,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -16,11 +16,12 @@ var (
Pauses one or more running containers. The container name or ID can be used.
`
pauseCommand = cli.Command{
Name: "pause",
Usage: "Pauses all the processes in one or more containers",
Description: pauseDescription,
Action: pauseCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
Name: "pause",
Usage: "Pauses all the processes in one or more containers",
Description: pauseDescription,
Action: pauseCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -29,5 +29,6 @@ Pods are a group of one or more containers sharing the same network, pid and ipc
Description: podDescription,
UseShortOptionHandling: true,
Subcommands: podSubCommands,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -74,6 +74,7 @@ var podCreateCommand = cli.Command{
HideHelp: true,
SkipArgReorder: true,
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
func podCreateCmd(c *cli.Context) error {

View File

@@ -23,6 +23,7 @@ var (
Action: podInspectCmd,
UseShortOptionHandling: true,
ArgsUsage: "[POD_NAME_OR_ID]",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -33,6 +33,7 @@ var (
Action: podKillCmd,
ArgsUsage: "[POD_NAME_OR_ID]",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -29,6 +29,7 @@ var (
Action: podPauseCmd,
ArgsUsage: "POD-NAME|POD-ID [POD-NAME|POD-ID ...]",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -164,6 +164,7 @@ var (
Flags: podPsFlags,
Action: podPsCmd,
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -27,6 +27,7 @@ var (
Action: podRestartCmd,
ArgsUsage: "POD-NAME|POD-ID [POD-NAME|POD-ID ...]",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -34,6 +34,7 @@ If --force is specified, all containers will be stopped, then removed.
Action: podRmCmd,
ArgsUsage: "[POD ...]",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -31,6 +31,7 @@ var (
Action: podStartCmd,
ArgsUsage: "POD-NAME [POD-NAME ...]",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -43,6 +43,7 @@ var (
Action: podStatsCmd,
ArgsUsage: "[POD_NAME_OR_ID]",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -24,12 +24,13 @@ var (
`
podStopCommand = cli.Command{
Name: "stop",
Usage: "Stop one or more pods",
Description: podStopDescription,
Flags: podStopFlags,
Action: podStopCmd,
ArgsUsage: "POD-NAME [POD-NAME ...]",
Name: "stop",
Usage: "Stop one or more pods",
Description: podStopDescription,
Flags: podStopFlags,
Action: podStopCmd,
ArgsUsage: "POD-NAME [POD-NAME ...]",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -36,6 +36,7 @@ the latest pod.
Action: podTopCmd,
ArgsUsage: "POD-NAME [format descriptors]",
SkipArgReorder: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -29,6 +29,7 @@ var (
Action: podUnpauseCmd,
ArgsUsage: "POD-NAME|POD-ID [POD-NAME|POD-ID ...]",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -26,12 +26,13 @@ var (
`
portCommand = cli.Command{
Name: "port",
Usage: "List port mappings or a specific mapping for the container",
Description: portDescription,
Flags: portFlags,
Action: portCmd,
ArgsUsage: "CONTAINER-NAME [mapping]",
Name: "port",
Usage: "List port mappings or a specific mapping for the container",
Description: portDescription,
Flags: portFlags,
Action: portCmd,
ArgsUsage: "CONTAINER-NAME [mapping]",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -186,6 +186,7 @@ var (
Action: psCmd,
ArgsUsage: "",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
lsCommand = cli.Command{
Name: "ls",
@@ -195,6 +196,7 @@ var (
Action: psCmd,
ArgsUsage: "",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -51,12 +51,13 @@ An image can be pulled using its tag or digest. If a tag is not
specified, the image with the 'latest' tag (if it exists) is pulled
`
pullCommand = cli.Command{
Name: "pull",
Usage: "Pull an image from a registry",
Description: pullDescription,
Flags: pullFlags,
Action: pullCmd,
ArgsUsage: "",
Name: "pull",
Usage: "Pull an image from a registry",
Description: pullDescription,
Flags: pullFlags,
Action: pullCmd,
ArgsUsage: "",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -67,12 +67,13 @@ var (
See podman-push(1) section "DESTINATION" for the expected format`)
pushCommand = cli.Command{
Name: "push",
Usage: "Push an image to a specified destination",
Description: pushDescription,
Flags: pushFlags,
Action: pushCmd,
ArgsUsage: "IMAGE DESTINATION",
Name: "push",
Usage: "Push an image to a specified destination",
Description: pushDescription,
Flags: pushFlags,
Action: pushCmd,
ArgsUsage: "IMAGE DESTINATION",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -21,6 +21,7 @@ var (
Flags: refreshFlags,
Action: refreshCmd,
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -30,6 +30,7 @@ var (
Action: restartCmd,
ArgsUsage: "CONTAINER [CONTAINER ...]",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -35,6 +35,7 @@ Running containers will not be removed without the -f option.
Action: rmCmd,
ArgsUsage: "",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -31,6 +31,7 @@ var (
ArgsUsage: "IMAGE-NAME-OR-ID [...]",
Flags: rmiFlags,
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
rmImageCommand = cli.Command{
Name: "rm",
@@ -40,6 +41,7 @@ var (
ArgsUsage: "IMAGE-NAME-OR-ID [...]",
Flags: rmiFlags,
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -37,6 +37,7 @@ var runCommand = cli.Command{
HideHelp: true,
SkipArgReorder: true,
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
func runCmd(c *cli.Context) error {

View File

@@ -57,6 +57,7 @@ var (
Action: saveCmd,
ArgsUsage: "",
SkipArgReorder: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -52,12 +52,13 @@ var (
Search registries for a given image. Can search all the default registries or a specific registry.
Can limit the number of results, and filter the output based on certain conditions.`
searchCommand = cli.Command{
Name: "search",
Usage: "Search registry for image",
Description: searchDescription,
Flags: searchFlags,
Action: searchCmd,
ArgsUsage: "TERM",
Name: "search",
Usage: "Search registry for image",
Description: searchDescription,
Flags: searchFlags,
Action: searchCmd,
ArgsUsage: "TERM",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -45,6 +45,7 @@ var (
Action: startCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
UseShortOptionHandling: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -49,12 +49,13 @@ var (
statsDescription = "display a live stream of one or more containers' resource usage statistics"
statsCommand = cli.Command{
Name: "stats",
Usage: "Display percentage of CPU, memory, network I/O, block I/O and PIDs for one or more containers",
Description: statsDescription,
Flags: statsFlags,
Action: statsCmd,
ArgsUsage: "",
Name: "stats",
Usage: "Display percentage of CPU, memory, network I/O, block I/O and PIDs for one or more containers",
Description: statsDescription,
Flags: statsFlags,
Action: statsCmd,
ArgsUsage: "",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -32,12 +32,13 @@ var (
`
stopCommand = cli.Command{
Name: "stop",
Usage: "Stop one or more containers",
Description: stopDescription,
Flags: stopFlags,
Action: stopCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
Name: "stop",
Usage: "Stop one or more containers",
Description: stopDescription,
Flags: stopFlags,
Action: stopCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -9,11 +9,12 @@ import (
var (
tagDescription = "Adds one or more additional names to locally-stored image"
tagCommand = cli.Command{
Name: "tag",
Usage: "Add an additional name to a local image",
Description: tagDescription,
Action: tagCmd,
ArgsUsage: "IMAGE-NAME [IMAGE-NAME ...]",
Name: "tag",
Usage: "Add an additional name to a local image",
Description: tagDescription,
Action: tagCmd,
ArgsUsage: "IMAGE-NAME [IMAGE-NAME ...]",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -46,6 +46,7 @@ the latest container.
Action: topCmd,
ArgsUsage: "CONTAINER-NAME [format descriptors]",
SkipArgReorder: true,
OnUsageError: usageErrorHandler,
}
)

View File

@@ -31,13 +31,14 @@ counter reaches zero indicating no other processes are using the mount.
An unmount can be forced with the --force flag.
`
umountCommand = cli.Command{
Name: "umount",
Aliases: []string{"unmount"},
Usage: "Unmounts working container's root filesystem",
Description: description,
Flags: umountFlags,
Action: umountCmd,
ArgsUsage: "CONTAINER-NAME-OR-ID",
Name: "umount",
Aliases: []string{"unmount"},
Usage: "Unmounts working container's root filesystem",
Description: description,
Flags: umountFlags,
Action: umountCmd,
ArgsUsage: "CONTAINER-NAME-OR-ID",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -16,11 +16,12 @@ var (
Unpauses one or more running containers. The container name or ID can be used.
`
unpauseCommand = cli.Command{
Name: "unpause",
Usage: "Unpause the processes in one or more containers",
Description: unpauseDescription,
Action: unpauseCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
Name: "unpause",
Usage: "Unpause the processes in one or more containers",
Description: unpauseDescription,
Action: unpauseCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -29,12 +29,13 @@ var (
},
}
varlinkCommand = &cli.Command{
Name: "varlink",
Usage: "Run varlink interface",
Description: varlinkDescription,
Flags: varlinkFlags,
Action: varlinkCmd,
ArgsUsage: "VARLINK_URI",
Name: "varlink",
Usage: "Run varlink interface",
Description: varlinkDescription,
Flags: varlinkFlags,
Action: varlinkCmd,
ArgsUsage: "VARLINK_URI",
OnUsageError: usageErrorHandler,
}
)

View File

@@ -17,12 +17,13 @@ var (
`
waitFlags = []cli.Flag{LatestFlag}
waitCommand = cli.Command{
Name: "wait",
Usage: "Block on one or more containers",
Description: waitDescription,
Flags: waitFlags,
Action: waitCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
Name: "wait",
Usage: "Block on one or more containers",
Description: waitDescription,
Flags: waitFlags,
Action: waitCmd,
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
OnUsageError: usageErrorHandler,
}
)