Files
docker-cli/components/engine/api/client/swarm/inspect.go
Daniel Nephin e808aa4ed0 Add Swarm management CLI commands
As described in our ROADMAP.md, introduce new Swarm management commands
to call to the corresponding API endpoints.

This PR is fully backward compatible (joining a Swarm is an optional
feature of the Engine, and existing commands are not impacted).

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Victor Vieux <vieux@docker.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Upstream-commit: 12a00e60177ca42bfb1dd9ebd5dce1c7039da6dd
Component: engine
2016-06-13 22:17:15 -07:00

57 lines
1.4 KiB
Go

package swarm
import (
"golang.org/x/net/context"
"github.com/docker/docker/api/client"
"github.com/docker/docker/api/client/inspect"
"github.com/docker/docker/cli"
"github.com/spf13/cobra"
)
type inspectOptions struct {
format string
// pretty bool
}
func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
var opts inspectOptions
cmd := &cobra.Command{
Use: "inspect [OPTIONS]",
Short: "Inspect the Swarm",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
// if opts.pretty && len(opts.format) > 0 {
// return fmt.Errorf("--format is incompatible with human friendly format")
// }
return runInspect(dockerCli, opts)
},
}
flags := cmd.Flags()
flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
//flags.BoolVarP(&opts.pretty, "pretty", "h", false, "Print the information in a human friendly format.")
return cmd
}
func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
client := dockerCli.Client()
ctx := context.Background()
swarm, err := client.SwarmInspect(ctx)
if err != nil {
return err
}
getRef := func(_ string) (interface{}, []byte, error) {
return swarm, nil, nil
}
// if !opts.pretty {
return inspect.Inspect(dockerCli.Out(), []string{""}, opts.format, getRef)
// }
//return printHumanFriendly(dockerCli.Out(), opts.refs, getRef)
}