summaryrefslogtreecommitdiff
path: root/cmd/podman/networks
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-11-13 16:46:51 +0100
committerGitHub <noreply@github.com>2020-11-13 16:46:51 +0100
commit2993e97dec9d998d2eca7c5aee918b1429596a85 (patch)
tree9bdb3b5c766d913a8d1980ad017276e1f1a51b7c /cmd/podman/networks
parent6d9d9fee30b5982858d51a666f0c335ba47323a0 (diff)
parentae3816614de1c2a0c9ab9cd05afebc5b1dda6429 (diff)
downloadpodman-2993e97dec9d998d2eca7c5aee918b1429596a85.tar.gz
podman-2993e97dec9d998d2eca7c5aee918b1429596a85.tar.bz2
podman-2993e97dec9d998d2eca7c5aee918b1429596a85.zip
Merge pull request #6442 from Luap99/podman-autocomplete
Shell completion
Diffstat (limited to 'cmd/podman/networks')
-rw-r--r--cmd/podman/networks/create.go51
-rw-r--r--cmd/podman/networks/inspect.go19
-rw-r--r--cmd/podman/networks/list.go28
-rw-r--r--cmd/podman/networks/rm.go14
4 files changed, 74 insertions, 38 deletions
diff --git a/cmd/podman/networks/create.go b/cmd/podman/networks/create.go
index c06011ce9..17de2c95d 100644
--- a/cmd/podman/networks/create.go
+++ b/cmd/podman/networks/create.go
@@ -4,22 +4,24 @@ import (
"fmt"
"net"
+ "github.com/containers/common/pkg/completion"
+ "github.com/containers/podman/v2/cmd/podman/common"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/spf13/cobra"
- "github.com/spf13/pflag"
)
var (
networkCreateDescription = `create CNI networks for containers and pods`
networkCreateCommand = &cobra.Command{
- Use: "create [options] [NETWORK]",
- Short: "network create",
- Long: networkCreateDescription,
- RunE: networkCreate,
- Args: cobra.MaximumNArgs(1),
- Example: `podman network create podman1`,
+ Use: "create [options] [NETWORK]",
+ Short: "network create",
+ Long: networkCreateDescription,
+ RunE: networkCreate,
+ Args: cobra.MaximumNArgs(1),
+ ValidArgsFunction: completion.AutocompleteNone,
+ Example: `podman network create podman1`,
}
)
@@ -27,16 +29,36 @@ var (
networkCreateOptions entities.NetworkCreateOptions
)
-func networkCreateFlags(flags *pflag.FlagSet) {
- flags.StringVarP(&networkCreateOptions.Driver, "driver", "d", "bridge", "driver to manage the network")
- flags.IPVar(&networkCreateOptions.Gateway, "gateway", nil, "IPv4 or IPv6 gateway for the subnet")
+func networkCreateFlags(cmd *cobra.Command) {
+ flags := cmd.Flags()
+
+ driverFlagName := "driver"
+ flags.StringVarP(&networkCreateOptions.Driver, driverFlagName, "d", "bridge", "driver to manage the network")
+ _ = cmd.RegisterFlagCompletionFunc(driverFlagName, common.AutocompleteNetworkDriver)
+
+ gatewayFlagName := "gateway"
+ flags.IPVar(&networkCreateOptions.Gateway, gatewayFlagName, nil, "IPv4 or IPv6 gateway for the subnet")
+ _ = cmd.RegisterFlagCompletionFunc(gatewayFlagName, completion.AutocompleteNone)
+
flags.BoolVar(&networkCreateOptions.Internal, "internal", false, "restrict external access from this network")
- flags.IPNetVar(&networkCreateOptions.Range, "ip-range", net.IPNet{}, "allocate container IP from range")
- flags.StringVar(&networkCreateOptions.MacVLAN, "macvlan", "", "create a Macvlan connection based on this device")
+
+ ipRangeFlagName := "ip-range"
+ flags.IPNetVar(&networkCreateOptions.Range, ipRangeFlagName, net.IPNet{}, "allocate container IP from range")
+ _ = cmd.RegisterFlagCompletionFunc(ipRangeFlagName, completion.AutocompleteNone)
+
+ macvlanFlagName := "macvlan"
+ flags.StringVar(&networkCreateOptions.MacVLAN, macvlanFlagName, "", "create a Macvlan connection based on this device")
+ _ = cmd.RegisterFlagCompletionFunc(macvlanFlagName, completion.AutocompleteNone)
+
// TODO not supported yet
// flags.StringVar(&networkCreateOptions.IPamDriver, "ipam-driver", "", "IP Address Management Driver")
+
flags.BoolVar(&networkCreateOptions.IPv6, "ipv6", false, "enable IPv6 networking")
- flags.IPNetVar(&networkCreateOptions.Subnet, "subnet", net.IPNet{}, "subnet in CIDR format")
+
+ subnetFlagName := "subnet"
+ flags.IPNetVar(&networkCreateOptions.Subnet, subnetFlagName, net.IPNet{}, "subnet in CIDR format")
+ _ = cmd.RegisterFlagCompletionFunc(subnetFlagName, completion.AutocompleteNone)
+
flags.BoolVar(&networkCreateOptions.DisableDNS, "disable-dns", false, "disable dns plugin")
}
func init() {
@@ -45,8 +67,7 @@ func init() {
Command: networkCreateCommand,
Parent: networkCmd,
})
- flags := networkCreateCommand.Flags()
- networkCreateFlags(flags)
+ networkCreateFlags(networkCreateCommand)
}
diff --git a/cmd/podman/networks/inspect.go b/cmd/podman/networks/inspect.go
index 25ee7e574..671b0265f 100644
--- a/cmd/podman/networks/inspect.go
+++ b/cmd/podman/networks/inspect.go
@@ -1,6 +1,7 @@
package network
import (
+ "github.com/containers/podman/v2/cmd/podman/common"
"github.com/containers/podman/v2/cmd/podman/inspect"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/pkg/domain/entities"
@@ -10,12 +11,13 @@ import (
var (
networkinspectDescription = `Inspect network`
networkinspectCommand = &cobra.Command{
- Use: "inspect [options] NETWORK [NETWORK...]",
- Short: "network inspect",
- Long: networkinspectDescription,
- RunE: networkInspect,
- Example: `podman network inspect podman`,
- Args: cobra.MinimumNArgs(1),
+ Use: "inspect [options] NETWORK [NETWORK...]",
+ Short: "network inspect",
+ Long: networkinspectDescription,
+ RunE: networkInspect,
+ Example: `podman network inspect podman`,
+ Args: cobra.MinimumNArgs(1),
+ ValidArgsFunction: common.AutocompleteNetworks,
}
inspectOpts *entities.InspectOptions
)
@@ -28,7 +30,10 @@ func init() {
})
inspectOpts = new(entities.InspectOptions)
flags := networkinspectCommand.Flags()
- flags.StringVarP(&inspectOpts.Format, "format", "f", "", "Pretty-print network to JSON or using a Go template")
+
+ formatFlagName := "format"
+ flags.StringVarP(&inspectOpts.Format, formatFlagName, "f", "", "Pretty-print network to JSON or using a Go template")
+ _ = networkinspectCommand.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteJSONFormat)
}
func networkInspect(_ *cobra.Command, args []string) error {
diff --git a/cmd/podman/networks/list.go b/cmd/podman/networks/list.go
index f68e4ed75..bab6b45ea 100644
--- a/cmd/podman/networks/list.go
+++ b/cmd/podman/networks/list.go
@@ -8,7 +8,9 @@ import (
"text/tabwriter"
"text/template"
+ "github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/report"
+ "github.com/containers/podman/v2/cmd/podman/common"
"github.com/containers/podman/v2/cmd/podman/parse"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/validate"
@@ -21,12 +23,13 @@ import (
var (
networklistDescription = `List networks`
networklistCommand = &cobra.Command{
- Use: "ls [options]",
- Args: validate.NoArgs,
- Short: "network list",
- Long: networklistDescription,
- RunE: networkList,
- Example: `podman network list`,
+ Use: "ls [options]",
+ Args: validate.NoArgs,
+ Short: "network list",
+ Long: networklistDescription,
+ RunE: networkList,
+ ValidArgsFunction: completion.AutocompleteNone,
+ Example: `podman network list`,
}
)
@@ -35,11 +38,16 @@ var (
)
func networkListFlags(flags *pflag.FlagSet) {
- // TODO enable filters based on something
- // flags.StringSliceVarP(&networklistCommand.Filter, "filter", "f", []string{}, "Pause all running containers")
- flags.StringVarP(&networkListOptions.Format, "format", "f", "", "Pretty-print networks to JSON or using a Go template")
+ formatFlagName := "format"
+ flags.StringVarP(&networkListOptions.Format, formatFlagName, "f", "", "Pretty-print networks to JSON or using a Go template")
+ _ = networklistCommand.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteJSONFormat)
+
flags.BoolVarP(&networkListOptions.Quiet, "quiet", "q", false, "display only names")
- flags.StringVarP(&networkListOptions.Filter, "filter", "", "", "Provide filter values (e.g. 'name=podman')")
+
+ filterFlagName := "filter"
+ flags.StringVarP(&networkListOptions.Filter, filterFlagName, "", "", "Provide filter values (e.g. 'name=podman')")
+ _ = networklistCommand.RegisterFlagCompletionFunc(filterFlagName, completion.AutocompleteNone)
+
}
func init() {
diff --git a/cmd/podman/networks/rm.go b/cmd/podman/networks/rm.go
index 3d7db941a..34e756a3a 100644
--- a/cmd/podman/networks/rm.go
+++ b/cmd/podman/networks/rm.go
@@ -4,6 +4,7 @@ import (
"fmt"
"strings"
+ "github.com/containers/podman/v2/cmd/podman/common"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/utils"
"github.com/containers/podman/v2/libpod/define"
@@ -16,12 +17,13 @@ import (
var (
networkrmDescription = `Remove networks`
networkrmCommand = &cobra.Command{
- Use: "rm [options] NETWORK [NETWORK...]",
- Short: "network rm",
- Long: networkrmDescription,
- RunE: networkRm,
- Example: `podman network rm podman`,
- Args: cobra.MinimumNArgs(1),
+ Use: "rm [options] NETWORK [NETWORK...]",
+ Short: "network rm",
+ Long: networkrmDescription,
+ RunE: networkRm,
+ Example: `podman network rm podman`,
+ Args: cobra.MinimumNArgs(1),
+ ValidArgsFunction: common.AutocompleteNetworks,
}
)