MCPcopy Index your code
hub / github.com/docker/cli / newDisconnectCommand

Function newDisconnectCommand

cli/command/network/disconnect.go:16–45  ·  view source on GitHub ↗
(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

14}
15
16func 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
47func isConnected(network string) func(container.Summary) bool {
48 return func(ctr container.Summary) bool {

Callers 2

newNetworkCommandFunction · 0.85

Calls 3

isConnectedFunction · 0.85
NetworkDisconnectMethod · 0.80
ClientMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…