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>
Upstream-commit: d7f6563efc
Component: cli
This commit is contained in:
Vincent Demeester
2017-05-15 14:45:19 +02:00
parent fd70e3c064
commit 242da31a23
48 changed files with 471 additions and 481 deletions
+2 -3
View File
@@ -1,14 +1,13 @@
package stack
import (
"golang.org/x/net/context"
"github.com/docker/cli/cli/compose/convert"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
"github.com/docker/docker/opts"
"golang.org/x/net/context"
)
func getStackFilter(namespace string) filters.Args {
+16 -17
View File
@@ -3,16 +3,15 @@ package stack
import (
"fmt"
"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/cli/command/idresolver"
"github.com/docker/cli/cli/command/task"
"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 psOptions struct {
@@ -25,33 +24,33 @@ type psOptions struct {
}
func newPsCommand(dockerCli command.Cli) *cobra.Command {
opts := psOptions{filter: opts.NewFilterOpt()}
options := psOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "ps [OPTIONS] STACK",
Short: "List the tasks in the stack",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.namespace = args[0]
return runPS(dockerCli, opts)
options.namespace = args[0]
return runPS(dockerCli, options)
},
}
flags := cmd.Flags()
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided")
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display task IDs")
flags.StringVar(&opts.format, "format", "", "Pretty-print tasks using a Go template")
flags.BoolVar(&options.noTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVar(&options.noResolve, "no-resolve", false, "Do not map IDs to Names")
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display task IDs")
flags.StringVar(&options.format, "format", "", "Pretty-print tasks using a Go template")
return cmd
}
func runPS(dockerCli command.Cli, opts psOptions) error {
namespace := opts.namespace
func runPS(dockerCli command.Cli, options psOptions) error {
namespace := options.namespace
client := dockerCli.Client()
ctx := context.Background()
filter := getStackFilterFromOpt(opts.namespace, opts.filter)
filter := getStackFilterFromOpt(options.namespace, options.filter)
tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter})
if err != nil {
@@ -63,14 +62,14 @@ func runPS(dockerCli command.Cli, opts psOptions) error {
return nil
}
format := opts.format
format := options.format
if len(format) == 0 {
if len(dockerCli.ConfigFile().TasksFormat) > 0 && !opts.quiet {
if len(dockerCli.ConfigFile().TasksFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().TasksFormat
} else {
format = formatter.TableFormatKey
}
}
return task.Print(ctx, dockerCli, tasks, idresolver.New(client, opts.noResolve), !opts.noTrunc, opts.quiet, format)
return task.Print(ctx, dockerCli, tasks, idresolver.New(client, options.noResolve), !options.noTrunc, options.quiet, format)
}
+15 -16
View File
@@ -3,16 +3,15 @@ package stack
import (
"fmt"
"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/cli/command/service"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/opts"
"github.com/spf13/cobra"
"golang.org/x/net/context"
)
type servicesOptions struct {
@@ -23,30 +22,30 @@ type servicesOptions struct {
}
func newServicesCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := servicesOptions{filter: opts.NewFilterOpt()}
options := servicesOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "services [OPTIONS] STACK",
Short: "List the services in the stack",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.namespace = args[0]
return runServices(dockerCli, opts)
options.namespace = args[0]
return runServices(dockerCli, options)
},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
flags.StringVar(&opts.format, "format", "", "Pretty-print services 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 services using a Go template")
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
return cmd
}
func runServices(dockerCli *command.DockerCli, opts servicesOptions) error {
func runServices(dockerCli *command.DockerCli, options servicesOptions) error {
ctx := context.Background()
client := dockerCli.Client()
filter := getStackFilterFromOpt(opts.namespace, opts.filter)
filter := getStackFilterFromOpt(options.namespace, options.filter)
services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: filter})
if err != nil {
return err
@@ -56,12 +55,12 @@ func runServices(dockerCli *command.DockerCli, opts servicesOptions) error {
// if no services in this stack, print message and exit 0
if len(services) == 0 {
fmt.Fprintf(out, "Nothing found in stack: %s\n", opts.namespace)
fmt.Fprintf(out, "Nothing found in stack: %s\n", options.namespace)
return nil
}
info := map[string]formatter.ServiceListInfo{}
if !opts.quiet {
if !options.quiet {
taskFilter := filters.NewArgs()
for _, service := range services {
taskFilter.Add("service", service.ID)
@@ -80,9 +79,9 @@ func runServices(dockerCli *command.DockerCli, opts servicesOptions) error {
info = service.GetServicesStatus(services, nodes, tasks)
}
format := opts.format
format := options.format
if len(format) == 0 {
if len(dockerCli.ConfigFile().ServicesFormat) > 0 && !opts.quiet {
if len(dockerCli.ConfigFile().ServicesFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().ServicesFormat
} else {
format = formatter.TableFormatKey
@@ -91,7 +90,7 @@ func runServices(dockerCli *command.DockerCli, opts servicesOptions) error {
servicesCtx := formatter.Context{
Output: dockerCli.Out(),
Format: formatter.NewServiceListFormat(format, opts.quiet),
Format: formatter.NewServiceListFormat(format, options.quiet),
}
return formatter.ServiceListWrite(servicesCtx, services, info)
}