Skip to content

Commit 3b2aa03

Browse files
committed
Usage messages: show possible option values
...in a consistent manner: ("a"|"b"|"c") This makes it possible (and easy) for zsh completion to pick those out of the --help messages and offer them as values when user hits TAB. I chose this format because it's an already-existing convention in cmd/podman/common.go. Also: removed two duplicate "default: x" messages (Cobra displays those automatically where a non-null default is specified). Signed-off-by: Ed Santiago <[email protected]>
1 parent c99b413 commit 3b2aa03

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

cmd/podman/common.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
308308
)
309309
createFlags.String(
310310
"image-volume", cliconfig.DefaultImageVolume,
311-
"Tells podman how to handle the builtin image volumes. The options are: 'bind', 'tmpfs', or 'ignore'",
311+
`Tells podman how to handle the builtin image volumes ("bind"|"tmpfs"|"ignore")`,
312312
)
313313
createFlags.Bool(
314314
"init", false,
@@ -431,7 +431,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
431431
)
432432
createFlags.String(
433433
"pull", "missing",
434-
`Pull image before creating ("always"|"missing"|"never") (default "missing")`,
434+
`Pull image before creating ("always"|"missing"|"never")`,
435435
)
436436
createFlags.BoolP(
437437
"quiet", "q", false,
@@ -447,7 +447,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
447447
)
448448
createFlags.String(
449449
"restart", "",
450-
"Restart policy to apply when a container exits",
450+
`Restart policy to apply when a container exits ("always"|"no"|"on-failure")`,
451451
)
452452
createFlags.Bool(
453453
"rm", false,
@@ -492,7 +492,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
492492
)
493493
createFlags.String(
494494
"systemd", "true",
495-
`Run container in systemd mode ("true"|"false"|"always" (default "true")`,
495+
`Run container in systemd mode ("true"|"false"|"always")`,
496496
)
497497
createFlags.StringArray(
498498
"tmpfs", []string{},

cmd/podman/main_local.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const remote = false
3333

3434
func init() {
3535
cgroupManager := define.SystemdCgroupsManager
36-
cgroupHelp := "Cgroup manager to use (cgroupfs or systemd)"
36+
cgroupHelp := `Cgroup manager to use ("cgroupfs"|"systemd")`
3737
cgroupv2, _ := cgroups.IsCgroup2UnifiedMode()
3838
if rootless.IsRootless() && !cgroupv2 {
3939
cgroupManager = ""
@@ -50,12 +50,12 @@ func init() {
5050
if err := rootCmd.PersistentFlags().MarkHidden("default-mounts-file"); err != nil {
5151
logrus.Error("unable to mark default-mounts-file flag as hidden")
5252
}
53-
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.EventsBackend, "events-backend", "", "Events backend to use")
53+
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.EventsBackend, "events-backend", "", `Events backend to use ("file"|"journald"|"none")`)
5454
// Override default --help information of `--help` global flag
5555
var dummyHelp bool
5656
rootCmd.PersistentFlags().BoolVar(&dummyHelp, "help", false, "Help for podman")
5757
rootCmd.PersistentFlags().StringSliceVar(&MainGlobalOpts.HooksDir, "hooks-dir", []string{}, "Set the OCI hooks directory path (may be set multiple times)")
58-
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.LogLevel, "log-level", "error", "Log messages above specified level: debug, info, warn, error, fatal or panic")
58+
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.LogLevel, "log-level", "error", `Log messages above specified level ("debug"|"info"|"warn"|"error"|"fatal"|"panic")`)
5959
rootCmd.PersistentFlags().IntVar(&MainGlobalOpts.MaxWorks, "max-workers", 0, "The maximum number of workers for parallel operations")
6060
if err := rootCmd.PersistentFlags().MarkHidden("max-workers"); err != nil {
6161
logrus.Error("unable to mark max-workers flag as hidden")

completions/zsh/_podman

+6-13
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,13 @@ _podman_find_helper() {
111111
elif expr "$desc" : ".*[Pp]ath" >/dev/null; then
112112
optval="path"
113113
helper=_files
114-
elif [ "$flags" = "--cgroup-manager" ]; then
115-
optval="cgroup manager"
116-
helper="(cgroupfs systemd)"
117-
elif [ "$flags" = "--log-level" ]; then
118-
optval="log level"
119-
# 'Log messages above specified level: debug, ... (default "...")'
120-
# Strip off the description and all 'default' strings
121-
desc=${desc/Log*:/} # debug, info, ... (default "...")
122-
desc=${(S)desc//\(*\)/} # debug, info, ... or panic
123-
desc=${desc//,/} # debug info ... or panic
124-
desc=${desc// or / } # debug info ... panic
125-
desc=${desc// / } # collapse multiple spaces
114+
# For messages like 'restart policy ("always"|"no"|"on-failure")
115+
elif optlist=$(expr "$desc" : '.*(\(\"[^\\)]\+|[^\\)]\+\"\))' 2>/dev/null); then
116+
optval=${${flags##--}//-/ } # "--log-level" => "log level"
117+
optlist=${optlist//\"/} # "a"|"b"|"c" => a|b|c
118+
optlist=${optlist//\|/ } # a|b|c => a b c
126119
# FIXME: how to present values _in order_, not sorted alphabetically?
127-
helper="($desc)"
120+
helper="($optlist)"
128121
fi
129122
echo "$optval:$helper"
130123
}

0 commit comments

Comments
 (0)