inspect.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package network
  2. import (
  3. "golang.org/x/net/context"
  4. "github.com/docker/docker/api/client"
  5. "github.com/docker/docker/api/client/inspect"
  6. "github.com/docker/docker/cli"
  7. "github.com/spf13/cobra"
  8. )
  9. type inspectOptions struct {
  10. format string
  11. names []string
  12. }
  13. func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
  14. var opts inspectOptions
  15. cmd := &cobra.Command{
  16. Use: "inspect [OPTIONS] NETWORK [NETWORK...]",
  17. Short: "Display detailed information on one or more networks",
  18. Args: cli.RequiresMinArgs(1),
  19. RunE: func(cmd *cobra.Command, args []string) error {
  20. opts.names = args
  21. return runInspect(dockerCli, opts)
  22. },
  23. }
  24. cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
  25. return cmd
  26. }
  27. func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
  28. client := dockerCli.Client()
  29. ctx := context.Background()
  30. getNetFunc := func(name string) (interface{}, []byte, error) {
  31. return client.NetworkInspectWithRaw(ctx, name)
  32. }
  33. return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getNetFunc)
  34. }