summaryrefslogtreecommitdiff
path: root/cmd/podman/system/connection
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2020-05-31 17:35:59 +0200
committerPaul Holzinger <paul.holzinger@web.de>2020-11-12 11:38:31 +0100
commitb5d1d89a377e38762a75c2042dcc50a370ba6707 (patch)
treeeebedb62f7aeeb17cd6fdbe9317a59effd02e96d /cmd/podman/system/connection
parentdf4bf5c584f264bdefef5cb30d85c036260eff8f (diff)
downloadpodman-b5d1d89a377e38762a75c2042dcc50a370ba6707.tar.gz
podman-b5d1d89a377e38762a75c2042dcc50a370ba6707.tar.bz2
podman-b5d1d89a377e38762a75c2042dcc50a370ba6707.zip
Add shell completion with cobra
Allow automatic generation for shell completion scripts with the internal cobra functions (requires v1.0.0+). This should replace the handwritten completion scripts and even adds support for fish. With this approach it is less likley that completions and code are out of sync. We can now create the scripts with - podman completion bash - podman completion zsh - podman completion fish To test the completion run: source <(podman completion bash) The same works for podman-remote and podman --remote and it will complete your remote containers/images with the correct endpoints values from --url/--connection. The completion logic is written in go and provided by the cobra library. The completion functions lives in `cmd/podman/completion/completion.go`. The unit test at cmd/podman/shell_completion_test.go checks if each command and flag has an autocompletion function set. This prevents that commands and flags have no shell completion set. This commit does not replace the current autocompletion scripts. Closes #6440 Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'cmd/podman/system/connection')
-rw-r--r--cmd/podman/system/connection/add.go20
-rw-r--r--cmd/podman/system/connection/default.go2
-rw-r--r--cmd/podman/system/connection/list.go6
-rw-r--r--cmd/podman/system/connection/remove.go2
-rw-r--r--cmd/podman/system/connection/rename.go2
5 files changed, 26 insertions, 6 deletions
diff --git a/cmd/podman/system/connection/add.go b/cmd/podman/system/connection/add.go
index 0d81a64ca..b3a23bffd 100644
--- a/cmd/podman/system/connection/add.go
+++ b/cmd/podman/system/connection/add.go
@@ -10,6 +10,7 @@ import (
"os/user"
"regexp"
+ "github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/system"
@@ -34,7 +35,8 @@ var (
"destination" is of the form [user@]hostname or
an URI of the form ssh://[user@]hostname[:port]
`,
- RunE: add,
+ RunE: add,
+ ValidArgsFunction: completion.AutocompleteNone,
Example: `podman system connection add laptop server.fubar.com
podman system connection add --identity ~/.ssh/dev_rsa testing ssh://root@server.fubar.com:2222
podman system connection add --identity ~/.ssh/dev_rsa --port 22 production root@server.fubar.com
@@ -57,9 +59,19 @@ func init() {
})
flags := addCmd.Flags()
- flags.IntVarP(&cOpts.Port, "port", "p", 22, "SSH port number for destination")
- flags.StringVar(&cOpts.Identity, "identity", "", "path to SSH identity file")
- flags.StringVar(&cOpts.UDSPath, "socket-path", "", "path to podman socket on remote host. (default '/run/podman/podman.sock' or '/run/user/{uid}/podman/podman.sock)")
+
+ portFlagName := "port"
+ flags.IntVarP(&cOpts.Port, portFlagName, "p", 22, "SSH port number for destination")
+ _ = addCmd.RegisterFlagCompletionFunc(portFlagName, completion.AutocompleteNone)
+
+ identityFlagName := "identity"
+ flags.StringVar(&cOpts.Identity, identityFlagName, "", "path to SSH identity file")
+ _ = addCmd.RegisterFlagCompletionFunc(identityFlagName, completion.AutocompleteDefault)
+
+ socketPathFlagName := "socket-path"
+ flags.StringVar(&cOpts.UDSPath, socketPathFlagName, "", "path to podman socket on remote host. (default '/run/podman/podman.sock' or '/run/user/{uid}/podman/podman.sock)")
+ _ = addCmd.RegisterFlagCompletionFunc(socketPathFlagName, completion.AutocompleteDefault)
+
flags.BoolVarP(&cOpts.Default, "default", "d", false, "Set connection to be default")
}
diff --git a/cmd/podman/system/connection/default.go b/cmd/podman/system/connection/default.go
index eafcf37b2..e2ae6ae7f 100644
--- a/cmd/podman/system/connection/default.go
+++ b/cmd/podman/system/connection/default.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/containers/common/pkg/config"
+ "github.com/containers/podman/v2/cmd/podman/common"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/system"
"github.com/containers/podman/v2/pkg/domain/entities"
@@ -18,6 +19,7 @@ var (
Short: "Set named destination as default",
Long: `Set named destination as default for the Podman service`,
DisableFlagsInUseLine: true,
+ ValidArgsFunction: common.AutocompleteSystemConnections,
RunE: defaultRunE,
Example: `podman system connection default testing`,
}
diff --git a/cmd/podman/system/connection/list.go b/cmd/podman/system/connection/list.go
index 9010ec803..b434559b4 100644
--- a/cmd/podman/system/connection/list.go
+++ b/cmd/podman/system/connection/list.go
@@ -5,6 +5,7 @@ import (
"text/tabwriter"
"text/template"
+ "github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/system"
@@ -23,8 +24,9 @@ var (
DisableFlagsInUseLine: true,
Example: `podman system connection list
podman system connection ls`,
- RunE: list,
- TraverseChildren: false,
+ ValidArgsFunction: completion.AutocompleteNone,
+ RunE: list,
+ TraverseChildren: false,
}
)
diff --git a/cmd/podman/system/connection/remove.go b/cmd/podman/system/connection/remove.go
index 58674efb6..429325f50 100644
--- a/cmd/podman/system/connection/remove.go
+++ b/cmd/podman/system/connection/remove.go
@@ -2,6 +2,7 @@ package connection
import (
"github.com/containers/common/pkg/config"
+ "github.com/containers/podman/v2/cmd/podman/common"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/system"
"github.com/containers/podman/v2/pkg/domain/entities"
@@ -17,6 +18,7 @@ var (
Long: `Delete named destination from podman configuration`,
Short: "Delete named destination",
DisableFlagsInUseLine: true,
+ ValidArgsFunction: common.AutocompleteSystemConnections,
RunE: rm,
Example: `podman system connection remove devl
podman system connection rm devl`,
diff --git a/cmd/podman/system/connection/rename.go b/cmd/podman/system/connection/rename.go
index bb2ca262a..7ab94d49a 100644
--- a/cmd/podman/system/connection/rename.go
+++ b/cmd/podman/system/connection/rename.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/containers/common/pkg/config"
+ "github.com/containers/podman/v2/cmd/podman/common"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/system"
"github.com/containers/podman/v2/pkg/domain/entities"
@@ -19,6 +20,7 @@ var (
Short: "Rename \"old\" to \"new\"",
Long: `Rename destination for the Podman service from "old" to "new"`,
DisableFlagsInUseLine: true,
+ ValidArgsFunction: common.AutocompleteSystemConnections,
RunE: rename,
Example: `podman system connection rename laptop devl,
podman system connection mv laptop devl`,