summaryrefslogtreecommitdiff
path: root/cmd/podman/common
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-05-16 21:01:52 +0200
committerPaul Holzinger <pholzing@redhat.com>2022-05-18 18:28:22 +0200
commit3b0844f990c6b7de708eeec1f8dfdc7e7d4611bd (patch)
tree1132b206bf7a98a79efe2b7de37f737b72207c18 /cmd/podman/common
parent3d8a1f91731b7935ae5239023d588a028dcd51e8 (diff)
downloadpodman-3b0844f990c6b7de708eeec1f8dfdc7e7d4611bd.tar.gz
podman-3b0844f990c6b7de708eeec1f8dfdc7e7d4611bd.tar.bz2
podman-3b0844f990c6b7de708eeec1f8dfdc7e7d4611bd.zip
shell completion --format: add help to function with args
From a template users POV it is not importent when they use a struct field or method. They only notice the difference when the function requires arguments. So lets be nice and let the user know that this method requires arguments via the help text. This is how it now looks like when the completion descriptions are enabled on bash: ``` $ bin/podman ps --format {{.Created.A {{.Created.AddDate (This is a function and requires 3 arguments) {{.Created.After (This is a function and requires 1 argument) {{.Created.Add (This is a function and requires 1 argument) {{.Created.AppendFormat (This is a function and requires 2 arguments) ``` Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'cmd/podman/common')
-rw-r--r--cmd/podman/common/completion.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index 32dd896c0..ce26c1678 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"reflect"
+ "strconv"
"strings"
"github.com/containers/common/libnetwork/types"
@@ -1142,6 +1143,20 @@ func getMethodNames(f reflect.Value, prefix string) []formatSuggestion {
if kind == reflect.Struct || kind == reflect.Map {
suffix = "."
}
+ // From a template users POV it is not importent when the use a struct field or method.
+ // They only notice the difference when the function requires arguments.
+ // So lets be nice and let the user know that this method requires arguments via the help text.
+ // Note since this is actually a method on a type the first argument is always fix so we should skip it.
+ num := method.Func.Type().NumIn() - 1
+ if num > 0 {
+ // everything after tab will the completion scripts show as help when enabled
+ // overwrite the suffix because it expects the args
+ suffix = "\tThis is a function and requires " + strconv.Itoa(num) + " argument"
+ if num > 1 {
+ // add plural s
+ suffix += "s"
+ }
+ }
fname := method.Name
if strings.HasPrefix(fname, prefix) {
// add method name with closing braces