inspect.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. }
  12. func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
  13. var opts inspectOptions
  14. cmd := &cobra.Command{
  15. Use: "inspect [OPTIONS]",
  16. Short: "Inspect the Swarm",
  17. Args: cli.NoArgs,
  18. RunE: func(cmd *cobra.Command, args []string) error {
  19. return runInspect(dockerCli, opts)
  20. },
  21. }
  22. flags := cmd.Flags()
  23. flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
  24. return cmd
  25. }
  26. func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
  27. client := dockerCli.Client()
  28. ctx := context.Background()
  29. swarm, err := client.SwarmInspect(ctx)
  30. if err != nil {
  31. return err
  32. }
  33. getRef := func(_ string) (interface{}, []byte, error) {
  34. return swarm, nil, nil
  35. }
  36. return inspect.Inspect(dockerCli.Out(), []string{""}, opts.format, getRef)
  37. }