inspect.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package swarm
  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. // pretty bool
  12. }
  13. func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
  14. var opts inspectOptions
  15. cmd := &cobra.Command{
  16. Use: "inspect [OPTIONS]",
  17. Short: "Inspect the Swarm",
  18. Args: cli.NoArgs,
  19. RunE: func(cmd *cobra.Command, args []string) error {
  20. // if opts.pretty && len(opts.format) > 0 {
  21. // return fmt.Errorf("--format is incompatible with human friendly format")
  22. // }
  23. return runInspect(dockerCli, opts)
  24. },
  25. }
  26. flags := cmd.Flags()
  27. flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
  28. //flags.BoolVarP(&opts.pretty, "pretty", "h", false, "Print the information in a human friendly format.")
  29. return cmd
  30. }
  31. func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
  32. client := dockerCli.Client()
  33. ctx := context.Background()
  34. swarm, err := client.SwarmInspect(ctx)
  35. if err != nil {
  36. return err
  37. }
  38. getRef := func(_ string) (interface{}, []byte, error) {
  39. return swarm, nil, nil
  40. }
  41. // if !opts.pretty {
  42. return inspect.Inspect(dockerCli.Out(), []string{""}, opts.format, getRef)
  43. // }
  44. //return printHumanFriendly(dockerCli.Out(), opts.refs, getRef)
  45. }