Skip to content

Commit

Permalink
Merge pull request #107 from rsteube/add-docker-network
Browse files Browse the repository at this point in the history
added docker network subcommand
  • Loading branch information
rsteube authored Sep 4, 2020
2 parents 98dc97f + 8c351e4 commit 70a0d7f
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 0 deletions.
11 changes: 11 additions & 0 deletions completers/docker_completer/cmd/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,14 @@ func ActionContexts() carapace.Action {
}
})
}

func ActionNetworks() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
if output, err := exec.Command("docker", "network", "ls", "--format", "{{.Name}}\n{{.Driver}}/{{.Scope}}").Output(); err != nil {
return carapace.ActionMessage(err.Error())
} else {
vals := strings.Split(string(output), "\n")
return carapace.ActionValuesDescribed(vals[:len(vals)-1]...)
}
})
}
18 changes: 18 additions & 0 deletions completers/docker_completer/cmd/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var networkCmd = &cobra.Command{
Use: "network",
Short: "Manage networks",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(networkCmd).Standalone()

rootCmd.AddCommand(networkCmd)
}
34 changes: 34 additions & 0 deletions completers/docker_completer/cmd/network_connect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action"
"github.com/spf13/cobra"
)

var network_connectCmd = &cobra.Command{
Use: "connect",
Short: "Connect a container to a network",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(network_connectCmd).Standalone()

network_connectCmd.Flags().String("alias", "", "Add network-scoped alias for the container")
network_connectCmd.Flags().String("driver-opt", "", "driver options for the network")
network_connectCmd.Flags().String("ip", "", "IPv4 address (e.g., 172.30.100.104)")
network_connectCmd.Flags().String("ip6", "", "IPv6 address (e.g., 2001:db8::33)")
network_connectCmd.Flags().String("link", "", "Add link to another container")
network_connectCmd.Flags().String("link-local-ip", "", "Add a link-local address for the container")
networkCmd.AddCommand(network_connectCmd)

carapace.Gen(network_connectCmd).FlagCompletion(carapace.ActionMap{
"link": action.ActionContainers(),
})

carapace.Gen(network_connectCmd).PositionalCompletion(
action.ActionNetworks(),
action.ActionContainers(),
)
}
44 changes: 44 additions & 0 deletions completers/docker_completer/cmd/network_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action"
"github.com/spf13/cobra"
)

var network_createCmd = &cobra.Command{
Use: "create",
Short: "Create a network",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(network_createCmd).Standalone()

network_createCmd.Flags().Bool("attachable", false, "Enable manual container attachment")
network_createCmd.Flags().String("aux-address", "", "Auxiliary IPv4 or IPv6 addresses used by Network driver (default map[])")
network_createCmd.Flags().String("config-from", "", "The network from which copying the configuration")
network_createCmd.Flags().Bool("config-only", false, "Create a configuration only network")
network_createCmd.Flags().StringP("driver", "d", "", "Driver to manage the Network (default \"bridge\")")
network_createCmd.Flags().String("gateway", "", "IPv4 or IPv6 Gateway for the master subnet")
network_createCmd.Flags().Bool("ingress", false, "Create swarm routing-mesh network")
network_createCmd.Flags().Bool("internal", false, "Restrict external access to the network")
network_createCmd.Flags().String("ip-range", "", "Allocate container ip from a sub-range")
network_createCmd.Flags().String("ipam-driver", "", "IP Address Management Driver (default \"default\")")
network_createCmd.Flags().String("ipam-opt", "", "Set IPAM driver specific options (default map[])")
network_createCmd.Flags().Bool("ipv6", false, "Enable IPv6 networking")
network_createCmd.Flags().String("label", "", "Set metadata on a network")
network_createCmd.Flags().StringP("opt", "o", "", "Set driver specific options (default map[])")
network_createCmd.Flags().String("scope", "", "Control the network's scope")
network_createCmd.Flags().String("subnet", "", "Subnet in CIDR format that represents a network segment")
networkCmd.AddCommand(network_createCmd)

carapace.Gen(network_createCmd).FlagCompletion(carapace.ActionMap{
"config-from": action.ActionNetworks(),
"driver": carapace.ActionValues("bridge", "host", "null", "overlay"),
})

carapace.Gen(network_createCmd).PositionalCompletion(
action.ActionNetworks(),
)
}
25 changes: 25 additions & 0 deletions completers/docker_completer/cmd/network_disconnect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action"
"github.com/spf13/cobra"
)

var network_disconnectCmd = &cobra.Command{
Use: "disconnect",
Short: "Disconnect a container from a network",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(network_disconnectCmd).Standalone()

network_disconnectCmd.Flags().BoolP("force", "f", false, "Force the container to disconnect from a network")
networkCmd.AddCommand(network_disconnectCmd)

carapace.Gen(network_disconnectCmd).PositionalCompletion(
action.ActionNetworks(),
action.ActionContainers(),
)
}
23 changes: 23 additions & 0 deletions completers/docker_completer/cmd/network_inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action"
"github.com/spf13/cobra"
)

var network_inspectCmd = &cobra.Command{
Use: "inspect",
Short: "Display detailed information on one or more networks",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(network_inspectCmd).Standalone()

network_inspectCmd.Flags().StringP("format", "f", "", "Format the output using the given Go template")
network_inspectCmd.Flags().BoolP("verbose", "v", false, "Verbose output for diagnostics")
networkCmd.AddCommand(network_inspectCmd)

carapace.Gen(network_inspectCmd).PositionalAnyCompletion(action.ActionNetworks())
}
22 changes: 22 additions & 0 deletions completers/docker_completer/cmd/network_ls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var network_lsCmd = &cobra.Command{
Use: "ls",
Short: "List networks",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(network_lsCmd).Standalone()

network_lsCmd.Flags().StringP("filter", "f", "", "Provide filter values (e.g. 'driver=bridge')")
network_lsCmd.Flags().String("format", "", "Pretty-print networks using a Go template")
network_lsCmd.Flags().Bool("no-trunc", false, "Do not truncate the output")
network_lsCmd.Flags().BoolP("quiet", "q", false, "Only display network IDs")
networkCmd.AddCommand(network_lsCmd)
}
20 changes: 20 additions & 0 deletions completers/docker_completer/cmd/network_prune.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var network_pruneCmd = &cobra.Command{
Use: "prune",
Short: "Remove all unused networks",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(network_pruneCmd).Standalone()

network_pruneCmd.Flags().String("filter", "", "Provide filter values (e.g. 'until=<timestamp>')")
network_pruneCmd.Flags().BoolP("force", "f", false, "Do not prompt for confirmation")
networkCmd.AddCommand(network_pruneCmd)
}
21 changes: 21 additions & 0 deletions completers/docker_completer/cmd/network_rm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action"
"github.com/spf13/cobra"
)

var network_rmCmd = &cobra.Command{
Use: "rm",
Short: "Remove one or more networks",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(network_rmCmd).Standalone()

networkCmd.AddCommand(network_rmCmd)

carapace.Gen(network_rmCmd).PositionalAnyCompletion(action.ActionNetworks())
}

0 comments on commit 70a0d7f

Please sign in to comment.