github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/cli/command/network/inspect.go (about) 1 package network 2 3 import ( 4 "context" 5 6 "github.com/docker/cli/cli" 7 "github.com/docker/cli/cli/command" 8 "github.com/docker/cli/cli/command/inspect" 9 "github.com/docker/docker/api/types" 10 "github.com/spf13/cobra" 11 ) 12 13 type inspectOptions struct { 14 format string 15 names []string 16 verbose bool 17 } 18 19 func newInspectCommand(dockerCli command.Cli) *cobra.Command { 20 var opts inspectOptions 21 22 cmd := &cobra.Command{ 23 Use: "inspect [OPTIONS] NETWORK [NETWORK...]", 24 Short: "Display detailed information on one or more networks", 25 Args: cli.RequiresMinArgs(1), 26 RunE: func(cmd *cobra.Command, args []string) error { 27 opts.names = args 28 return runInspect(dockerCli, opts) 29 }, 30 } 31 32 cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") 33 cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "Verbose output for diagnostics") 34 35 return cmd 36 } 37 38 func runInspect(dockerCli command.Cli, opts inspectOptions) error { 39 client := dockerCli.Client() 40 41 ctx := context.Background() 42 43 getNetFunc := func(name string) (interface{}, []byte, error) { 44 return client.NetworkInspectWithRaw(ctx, name, types.NetworkInspectOptions{Verbose: opts.verbose}) 45 } 46 47 return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getNetFunc) 48 }