github.com/olljanat/moby@v1.13.1/cli/command/network/remove.go (about)

     1  package network
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"golang.org/x/net/context"
     7  
     8  	"github.com/docker/docker/cli"
     9  	"github.com/docker/docker/cli/command"
    10  	"github.com/spf13/cobra"
    11  )
    12  
    13  func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
    14  	return &cobra.Command{
    15  		Use:     "rm NETWORK [NETWORK...]",
    16  		Aliases: []string{"remove"},
    17  		Short:   "Remove one or more networks",
    18  		Args:    cli.RequiresMinArgs(1),
    19  		RunE: func(cmd *cobra.Command, args []string) error {
    20  			return runRemove(dockerCli, args)
    21  		},
    22  	}
    23  }
    24  
    25  func runRemove(dockerCli *command.DockerCli, networks []string) error {
    26  	client := dockerCli.Client()
    27  	ctx := context.Background()
    28  	status := 0
    29  
    30  	for _, name := range networks {
    31  		if err := client.NetworkRemove(ctx, name); err != nil {
    32  			fmt.Fprintf(dockerCli.Err(), "%s\n", err)
    33  			status = 1
    34  			continue
    35  		}
    36  		fmt.Fprintf(dockerCli.Out(), "%s\n", name)
    37  	}
    38  
    39  	if status != 0 {
    40  		return cli.StatusError{StatusCode: status}
    41  	}
    42  	return nil
    43  }