(dockerCLI command.Cli)
| 14 | } |
| 15 | |
| 16 | func newDisconnectCommand(dockerCLI command.Cli) *cobra.Command { |
| 17 | opts := disconnectOptions{} |
| 18 | |
| 19 | cmd := &cobra.Command{ |
| 20 | Use: "disconnect [OPTIONS] NETWORK CONTAINER", |
| 21 | Short: "Disconnect a container from a network", |
| 22 | Args: cli.ExactArgs(2), |
| 23 | RunE: func(cmd *cobra.Command, args []string) error { |
| 24 | network := args[0] |
| 25 | _, err := dockerCLI.Client().NetworkDisconnect(cmd.Context(), network, client.NetworkDisconnectOptions{ |
| 26 | Container: args[1], |
| 27 | Force: opts.force, |
| 28 | }) |
| 29 | return err |
| 30 | }, |
| 31 | ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 32 | if len(args) == 0 { |
| 33 | return completion.NetworkNames(dockerCLI)(cmd, args, toComplete) |
| 34 | } |
| 35 | nw := args[0] |
| 36 | return completion.ContainerNames(dockerCLI, true, isConnected(nw))(cmd, args, toComplete) |
| 37 | }, |
| 38 | DisableFlagsInUseLine: true, |
| 39 | } |
| 40 | |
| 41 | flags := cmd.Flags() |
| 42 | flags.BoolVarP(&opts.force, "force", "f", false, "Force the container to disconnect from a network") |
| 43 | |
| 44 | return cmd |
| 45 | } |
| 46 | |
| 47 | func isConnected(network string) func(container.Summary) bool { |
| 48 | return func(ctr container.Summary) bool { |
searching dependent graphs…