mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
12a00e6017
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>
56 lines
1.4 KiB
Go
56 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)
|
|
}
|