github.com/kunnos/engine@v1.13.1/cli/command/network/disconnect.go (about) 1 package network 2 3 import ( 4 "golang.org/x/net/context" 5 6 "github.com/docker/docker/cli" 7 "github.com/docker/docker/cli/command" 8 "github.com/spf13/cobra" 9 ) 10 11 type disconnectOptions struct { 12 network string 13 container string 14 force bool 15 } 16 17 func newDisconnectCommand(dockerCli *command.DockerCli) *cobra.Command { 18 opts := disconnectOptions{} 19 20 cmd := &cobra.Command{ 21 Use: "disconnect [OPTIONS] NETWORK CONTAINER", 22 Short: "Disconnect a container from a network", 23 Args: cli.ExactArgs(2), 24 RunE: func(cmd *cobra.Command, args []string) error { 25 opts.network = args[0] 26 opts.container = args[1] 27 return runDisconnect(dockerCli, opts) 28 }, 29 } 30 31 flags := cmd.Flags() 32 flags.BoolVarP(&opts.force, "force", "f", false, "Force the container to disconnect from a network") 33 34 return cmd 35 } 36 37 func runDisconnect(dockerCli *command.DockerCli, opts disconnectOptions) error { 38 client := dockerCli.Client() 39 40 return client.NetworkDisconnect(context.Background(), opts.network, opts.container, opts.force) 41 }