Update cli imports to using local package

Also, rename a bunch of variable to not *shadow* the `opts` package
name.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester
2017-05-15 14:45:19 +02:00
parent 560dc7660f
commit d7f6563efc
48 changed files with 471 additions and 481 deletions

View File

@ -1,14 +1,13 @@
package node
import (
"golang.org/x/net/context"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
"github.com/docker/docker/opts"
"github.com/spf13/cobra"
"golang.org/x/net/context"
)
type listOptions struct {
@ -18,7 +17,7 @@ type listOptions struct {
}
func newListCommand(dockerCli command.Cli) *cobra.Command {
opts := listOptions{filter: opts.NewFilterOpt()}
options := listOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "ls [OPTIONS]",
@ -26,30 +25,30 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
Short: "List nodes in the swarm",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runList(dockerCli, opts)
return runList(dockerCli, options)
},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
flags.StringVar(&opts.format, "format", "", "Pretty-print nodes using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided")
flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display IDs")
flags.StringVar(&options.format, "format", "", "Pretty-print nodes using a Go template")
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
return cmd
}
func runList(dockerCli command.Cli, opts listOptions) error {
func runList(dockerCli command.Cli, options listOptions) error {
client := dockerCli.Client()
ctx := context.Background()
nodes, err := client.NodeList(
ctx,
types.NodeListOptions{Filters: opts.filter.Value()})
types.NodeListOptions{Filters: options.filter.Value()})
if err != nil {
return err
}
info := types.Info{}
if len(nodes) > 0 && !opts.quiet {
if len(nodes) > 0 && !options.quiet {
// only non-empty nodes and not quiet, should we call /info api
info, err = client.Info(ctx)
if err != nil {
@ -57,17 +56,17 @@ func runList(dockerCli command.Cli, opts listOptions) error {
}
}
format := opts.format
format := options.format
if len(format) == 0 {
format = formatter.TableFormatKey
if len(dockerCli.ConfigFile().NodesFormat) > 0 && !opts.quiet {
if len(dockerCli.ConfigFile().NodesFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().NodesFormat
}
}
nodesCtx := formatter.Context{
Output: dockerCli.Out(),
Format: formatter.NewNodeFormat(format, opts.quiet),
Format: formatter.NewNodeFormat(format, options.quiet),
}
return formatter.NodeWrite(nodesCtx, nodes, info)
}