summaryrefslogtreecommitdiff
path: root/cmd/podman/pods/create.go
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/pods/create.go
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/pods/create.go')
-rw-r--r--cmd/podman/pods/create.go68
1 files changed, 52 insertions, 16 deletions
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index efa84dcb4..d33455e81 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -7,6 +7,7 @@ import (
"os"
"strings"
+ "github.com/containers/common/pkg/completion"
"github.com/containers/podman/v2/cmd/podman/common"
"github.com/containers/podman/v2/cmd/podman/parse"
"github.com/containers/podman/v2/cmd/podman/registry"
@@ -27,11 +28,12 @@ var (
You can then start it at any time with the podman pod start <pod_id> command. The pod will be created with the initial state 'created'.`
createCommand = &cobra.Command{
- Use: "create [options]",
- Args: validate.NoArgs,
- Short: "Create a new empty pod",
- Long: podCreateDescription,
- RunE: create,
+ Use: "create [options]",
+ Args: validate.NoArgs,
+ Short: "Create a new empty pod",
+ Long: podCreateDescription,
+ RunE: create,
+ ValidArgsFunction: completion.AutocompleteNone,
}
)
@@ -51,19 +53,53 @@ func init() {
})
flags := createCommand.Flags()
flags.SetInterspersed(false)
- flags.AddFlagSet(common.GetNetFlags())
- flags.StringVar(&createOptions.CGroupParent, "cgroup-parent", "", "Set parent cgroup for the pod")
+
+ common.DefineNetFlags(createCommand)
+
+ cgroupParentflagName := "cgroup-parent"
+ flags.StringVar(&createOptions.CGroupParent, cgroupParentflagName, "", "Set parent cgroup for the pod")
+ _ = createCommand.RegisterFlagCompletionFunc(cgroupParentflagName, completion.AutocompleteDefault)
+
flags.BoolVar(&createOptions.Infra, "infra", true, "Create an infra container associated with the pod to share namespaces with")
- flags.StringVar(&createOptions.InfraConmonPidFile, "infra-conmon-pidfile", "", "Path to the file that will receive the POD of the infra container's conmon")
- flags.String("infra-image", containerConfig.Engine.InfraImage, "The image of the infra container to associate with the pod")
- flags.String("infra-command", containerConfig.Engine.InfraCommand, "The command to run on the infra container when the pod is started")
- flags.StringSliceVar(&labelFile, "label-file", []string{}, "Read in a line delimited file of labels")
- flags.StringSliceVarP(&labels, "label", "l", []string{}, "Set metadata on pod (default [])")
- flags.StringVarP(&createOptions.Name, "name", "n", "", "Assign a name to the pod")
- flags.StringVarP(&createOptions.Hostname, "hostname", "", "", "Set a hostname to the pod")
- flags.StringVar(&podIDFile, "pod-id-file", "", "Write the pod ID to the file")
+
+ infraConmonPidfileFlagName := "infra-conmon-pidfile"
+ flags.StringVar(&createOptions.InfraConmonPidFile, infraConmonPidfileFlagName, "", "Path to the file that will receive the POD of the infra container's conmon")
+ _ = createCommand.RegisterFlagCompletionFunc(infraConmonPidfileFlagName, completion.AutocompleteDefault)
+
+ infraImageFlagName := "infra-image"
+ flags.String(infraImageFlagName, containerConfig.Engine.InfraImage, "The image of the infra container to associate with the pod")
+ _ = createCommand.RegisterFlagCompletionFunc(infraImageFlagName, common.AutocompleteImages)
+
+ infraCommandFlagName := "infra-command"
+ flags.String(infraCommandFlagName, containerConfig.Engine.InfraCommand, "The command to run on the infra container when the pod is started")
+ _ = createCommand.RegisterFlagCompletionFunc(infraCommandFlagName, completion.AutocompleteNone)
+
+ labelFileFlagName := "label-file"
+ flags.StringSliceVar(&labelFile, labelFileFlagName, []string{}, "Read in a line delimited file of labels")
+ _ = createCommand.RegisterFlagCompletionFunc(labelFileFlagName, completion.AutocompleteDefault)
+
+ labelFlagName := "label"
+ flags.StringSliceVarP(&labels, labelFlagName, "l", []string{}, "Set metadata on pod (default [])")
+ _ = createCommand.RegisterFlagCompletionFunc(labelFlagName, completion.AutocompleteNone)
+
+ nameFlagName := "name"
+ flags.StringVarP(&createOptions.Name, nameFlagName, "n", "", "Assign a name to the pod")
+ _ = createCommand.RegisterFlagCompletionFunc(nameFlagName, completion.AutocompleteNone)
+
+ hostnameFlagName := "hostname"
+ flags.StringVarP(&createOptions.Hostname, hostnameFlagName, "", "", "Set a hostname to the pod")
+ _ = createCommand.RegisterFlagCompletionFunc(hostnameFlagName, completion.AutocompleteNone)
+
+ podIDFileFlagName := "pod-id-file"
+ flags.StringVar(&podIDFile, podIDFileFlagName, "", "Write the pod ID to the file")
+ _ = createCommand.RegisterFlagCompletionFunc(podIDFileFlagName, completion.AutocompleteDefault)
+
flags.BoolVar(&replace, "replace", false, "If a pod with the same exists, replace it")
- flags.StringVar(&share, "share", specgen.DefaultKernelNamespaces, "A comma delimited list of kernel namespaces the pod will share")
+
+ shareFlagName := "share"
+ flags.StringVar(&share, shareFlagName, specgen.DefaultKernelNamespaces, "A comma delimited list of kernel namespaces the pod will share")
+ _ = createCommand.RegisterFlagCompletionFunc(shareFlagName, common.AutocompletePodShareNamespace)
+
flags.SetNormalizeFunc(aliasNetworkFlag)
}