github.com/kunnos/engine@v1.13.1/cli/command/network/inspect.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/docker/docker/cli/command/inspect"
     9  	"github.com/spf13/cobra"
    10  )
    11  
    12  type inspectOptions struct {
    13  	format string
    14  	names  []string
    15  }
    16  
    17  func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
    18  	var opts inspectOptions
    19  
    20  	cmd := &cobra.Command{
    21  		Use:   "inspect [OPTIONS] NETWORK [NETWORK...]",
    22  		Short: "Display detailed information on one or more networks",
    23  		Args:  cli.RequiresMinArgs(1),
    24  		RunE: func(cmd *cobra.Command, args []string) error {
    25  			opts.names = args
    26  			return runInspect(dockerCli, opts)
    27  		},
    28  	}
    29  
    30  	cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
    31  
    32  	return cmd
    33  }
    34  
    35  func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
    36  	client := dockerCli.Client()
    37  
    38  	ctx := context.Background()
    39  
    40  	getNetFunc := func(name string) (interface{}, []byte, error) {
    41  		return client.NetworkInspectWithRaw(ctx, name)
    42  	}
    43  
    44  	return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getNetFunc)
    45  }