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
No known key found for this signature in database
GPG Key ID: 083CC6FD6EB699A3
48 changed files with 471 additions and 481 deletions

View File

@ -12,11 +12,11 @@ import (
"github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/config/credentials" "github.com/docker/cli/cli/config/credentials"
cliflags "github.com/docker/cli/cli/flags" cliflags "github.com/docker/cli/cli/flags"
dopts "github.com/docker/cli/opts"
"github.com/docker/docker/api" "github.com/docker/docker/api"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client" "github.com/docker/docker/client"
dopts "github.com/docker/docker/opts"
"github.com/docker/go-connections/sockets" "github.com/docker/go-connections/sockets"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
"github.com/docker/notary/passphrase" "github.com/docker/notary/passphrase"

View File

@ -7,8 +7,8 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/pkg/errors" "github.com/pkg/errors"

View File

@ -4,8 +4,8 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -17,7 +17,7 @@ type listOptions struct {
} }
func newConfigListCommand(dockerCli command.Cli) *cobra.Command { func newConfigListCommand(dockerCli command.Cli) *cobra.Command {
opts := listOptions{filter: opts.NewFilterOpt()} listOpts := listOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ls [OPTIONS]", Use: "ls [OPTIONS]",
@ -25,30 +25,30 @@ func newConfigListCommand(dockerCli command.Cli) *cobra.Command {
Short: "List configs", Short: "List configs",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runConfigList(dockerCli, opts) return runConfigList(dockerCli, listOpts)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") flags.BoolVarP(&listOpts.quiet, "quiet", "q", false, "Only display IDs")
flags.StringVarP(&opts.format, "format", "", "", "Pretty-print configs using a Go template") flags.StringVarP(&listOpts.format, "format", "", "", "Pretty-print configs using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&listOpts.filter, "filter", "f", "Filter output based on conditions provided")
return cmd return cmd
} }
func runConfigList(dockerCli command.Cli, opts listOptions) error { func runConfigList(dockerCli command.Cli, options listOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
configs, err := client.ConfigList(ctx, types.ConfigListOptions{Filters: opts.filter.Value()}) configs, err := client.ConfigList(ctx, types.ConfigListOptions{Filters: options.filter.Value()})
if err != nil { if err != nil {
return err return err
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().ConfigFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().ConfigFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().ConfigFormat format = dockerCli.ConfigFile().ConfigFormat
} else { } else {
format = formatter.TableFormatKey format = formatter.TableFormatKey
@ -57,7 +57,7 @@ func runConfigList(dockerCli command.Cli, opts listOptions) error {
configCtx := formatter.Context{ configCtx := formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: formatter.NewConfigFormat(format, opts.quiet), Format: formatter.NewConfigFormat(format, options.quiet),
} }
return formatter.ConfigWrite(configCtx, configs) return formatter.ConfigWrite(configCtx, configs)
} }

View File

@ -5,8 +5,8 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
dockeropts "github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -18,54 +18,54 @@ type commitOptions struct {
pause bool pause bool
comment string comment string
author string author string
changes dockeropts.ListOpts changes opts.ListOpts
} }
// NewCommitCommand creates a new cobra.Command for `docker commit` // NewCommitCommand creates a new cobra.Command for `docker commit`
func NewCommitCommand(dockerCli *command.DockerCli) *cobra.Command { func NewCommitCommand(dockerCli *command.DockerCli) *cobra.Command {
var opts commitOptions var options commitOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]", Use: "commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]",
Short: "Create a new image from a container's changes", Short: "Create a new image from a container's changes",
Args: cli.RequiresRangeArgs(1, 2), Args: cli.RequiresRangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
opts.container = args[0] options.container = args[0]
if len(args) > 1 { if len(args) > 1 {
opts.reference = args[1] options.reference = args[1]
} }
return runCommit(dockerCli, &opts) return runCommit(dockerCli, &options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.SetInterspersed(false) flags.SetInterspersed(false)
flags.BoolVarP(&opts.pause, "pause", "p", true, "Pause container during commit") flags.BoolVarP(&options.pause, "pause", "p", true, "Pause container during commit")
flags.StringVarP(&opts.comment, "message", "m", "", "Commit message") flags.StringVarP(&options.comment, "message", "m", "", "Commit message")
flags.StringVarP(&opts.author, "author", "a", "", "Author (e.g., \"John Hannibal Smith <hannibal@a-team.com>\")") flags.StringVarP(&options.author, "author", "a", "", "Author (e.g., \"John Hannibal Smith <hannibal@a-team.com>\")")
opts.changes = dockeropts.NewListOpts(nil) options.changes = opts.NewListOpts(nil)
flags.VarP(&opts.changes, "change", "c", "Apply Dockerfile instruction to the created image") flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image")
return cmd return cmd
} }
func runCommit(dockerCli *command.DockerCli, opts *commitOptions) error { func runCommit(dockerCli *command.DockerCli, options *commitOptions) error {
ctx := context.Background() ctx := context.Background()
name := opts.container name := options.container
reference := opts.reference reference := options.reference
options := types.ContainerCommitOptions{ commitOptions := types.ContainerCommitOptions{
Reference: reference, Reference: reference,
Comment: opts.comment, Comment: options.comment,
Author: opts.author, Author: options.author,
Changes: opts.changes.GetAll(), Changes: options.changes.GetAll(),
Pause: opts.pause, Pause: options.pause,
} }
response, err := dockerCli.Client().ContainerCommit(ctx, name, options) response, err := dockerCli.Client().ContainerCommit(ctx, name, commitOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@ -7,9 +7,9 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
apiclient "github.com/docker/docker/client" apiclient "github.com/docker/docker/client"
options "github.com/docker/docker/opts"
"github.com/docker/docker/pkg/promise" "github.com/docker/docker/pkg/promise"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -22,19 +22,19 @@ type execOptions struct {
detach bool detach bool
user string user string
privileged bool privileged bool
env *options.ListOpts env *opts.ListOpts
} }
func newExecOptions() *execOptions { func newExecOptions() *execOptions {
var values []string var values []string
return &execOptions{ return &execOptions{
env: options.NewListOptsRef(&values, options.ValidateEnv), env: opts.NewListOptsRef(&values, opts.ValidateEnv),
} }
} }
// NewExecCommand creates a new cobra.Command for `docker exec` // NewExecCommand creates a new cobra.Command for `docker exec`
func NewExecCommand(dockerCli *command.DockerCli) *cobra.Command { func NewExecCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := newExecOptions() options := newExecOptions()
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "exec [OPTIONS] CONTAINER COMMAND [ARG...]", Use: "exec [OPTIONS] CONTAINER COMMAND [ARG...]",
@ -43,35 +43,35 @@ func NewExecCommand(dockerCli *command.DockerCli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
container := args[0] container := args[0]
execCmd := args[1:] execCmd := args[1:]
return runExec(dockerCli, opts, container, execCmd) return runExec(dockerCli, options, container, execCmd)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.SetInterspersed(false) flags.SetInterspersed(false)
flags.StringVarP(&opts.detachKeys, "detach-keys", "", "", "Override the key sequence for detaching a container") flags.StringVarP(&options.detachKeys, "detach-keys", "", "", "Override the key sequence for detaching a container")
flags.BoolVarP(&opts.interactive, "interactive", "i", false, "Keep STDIN open even if not attached") flags.BoolVarP(&options.interactive, "interactive", "i", false, "Keep STDIN open even if not attached")
flags.BoolVarP(&opts.tty, "tty", "t", false, "Allocate a pseudo-TTY") flags.BoolVarP(&options.tty, "tty", "t", false, "Allocate a pseudo-TTY")
flags.BoolVarP(&opts.detach, "detach", "d", false, "Detached mode: run command in the background") flags.BoolVarP(&options.detach, "detach", "d", false, "Detached mode: run command in the background")
flags.StringVarP(&opts.user, "user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])") flags.StringVarP(&options.user, "user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
flags.BoolVarP(&opts.privileged, "privileged", "", false, "Give extended privileges to the command") flags.BoolVarP(&options.privileged, "privileged", "", false, "Give extended privileges to the command")
flags.VarP(opts.env, "env", "e", "Set environment variables") flags.VarP(options.env, "env", "e", "Set environment variables")
flags.SetAnnotation("env", "version", []string{"1.25"}) flags.SetAnnotation("env", "version", []string{"1.25"})
return cmd return cmd
} }
// nolint: gocyclo // nolint: gocyclo
func runExec(dockerCli *command.DockerCli, opts *execOptions, container string, execCmd []string) error { func runExec(dockerCli *command.DockerCli, options *execOptions, container string, execCmd []string) error {
execConfig, err := parseExec(opts, execCmd) execConfig, err := parseExec(options, execCmd)
// just in case the ParseExec does not exit // just in case the ParseExec does not exit
if container == "" || err != nil { if container == "" || err != nil {
return cli.StatusError{StatusCode: 1} return cli.StatusError{StatusCode: 1}
} }
if opts.detachKeys != "" { if options.detachKeys != "" {
dockerCli.ConfigFile().DetachKeys = opts.detachKeys dockerCli.ConfigFile().DetachKeys = options.detachKeys
} }
// Send client escape keys // Send client escape keys

View File

@ -6,8 +6,8 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/templates" "github.com/docker/docker/pkg/templates"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -26,27 +26,27 @@ type psOptions struct {
// NewPsCommand creates a new cobra.Command for `docker ps` // NewPsCommand creates a new cobra.Command for `docker ps`
func NewPsCommand(dockerCli *command.DockerCli) *cobra.Command { func NewPsCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := psOptions{filter: opts.NewFilterOpt()} options := psOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ps [OPTIONS]", Use: "ps [OPTIONS]",
Short: "List containers", Short: "List containers",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runPs(dockerCli, &opts) return runPs(dockerCli, &options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display numeric IDs") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display numeric IDs")
flags.BoolVarP(&opts.size, "size", "s", false, "Display total file sizes") flags.BoolVarP(&options.size, "size", "s", false, "Display total file sizes")
flags.BoolVarP(&opts.all, "all", "a", false, "Show all containers (default shows just running)") flags.BoolVarP(&options.all, "all", "a", false, "Show all containers (default shows just running)")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output")
flags.BoolVarP(&opts.nLatest, "latest", "l", false, "Show the latest created container (includes all states)") flags.BoolVarP(&options.nLatest, "latest", "l", false, "Show the latest created container (includes all states)")
flags.IntVarP(&opts.last, "last", "n", -1, "Show n last created containers (includes all states)") flags.IntVarP(&options.last, "last", "n", -1, "Show n last created containers (includes all states)")
flags.StringVarP(&opts.format, "format", "", "", "Pretty-print containers using a Go template") flags.StringVarP(&options.format, "format", "", "", "Pretty-print containers using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
return cmd return cmd
} }
@ -109,10 +109,10 @@ func buildContainerListOptions(opts *psOptions) (*types.ContainerListOptions, er
return options, nil return options, nil
} }
func runPs(dockerCli *command.DockerCli, opts *psOptions) error { func runPs(dockerCli *command.DockerCli, options *psOptions) error {
ctx := context.Background() ctx := context.Background()
listOptions, err := buildContainerListOptions(opts) listOptions, err := buildContainerListOptions(options)
if err != nil { if err != nil {
return err return err
} }
@ -122,9 +122,9 @@ func runPs(dockerCli *command.DockerCli, opts *psOptions) error {
return err return err
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().PsFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().PsFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().PsFormat format = dockerCli.ConfigFile().PsFormat
} else { } else {
format = formatter.TableFormatKey format = formatter.TableFormatKey
@ -133,8 +133,8 @@ func runPs(dockerCli *command.DockerCli, opts *psOptions) error {
containerCtx := formatter.Context{ containerCtx := formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: formatter.NewContainerFormat(format, opts.quiet, listOptions.Size), Format: formatter.NewContainerFormat(format, options.quiet, listOptions.Size),
Trunc: !opts.noTrunc, Trunc: !options.noTrunc,
} }
return formatter.ContainerWrite(containerCtx, containers) return formatter.ContainerWrite(containerCtx, containers)
} }

View File

@ -12,10 +12,10 @@ import (
"time" "time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
networktypes "github.com/docker/docker/api/types/network" networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/strslice" "github.com/docker/docker/api/types/strslice"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/signal"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"

View File

@ -5,7 +5,7 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
units "github.com/docker/go-units" units "github.com/docker/go-units"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -18,14 +18,14 @@ type pruneOptions struct {
// NewPruneCommand returns a new cobra prune command for containers // NewPruneCommand returns a new cobra prune command for containers
func NewPruneCommand(dockerCli command.Cli) *cobra.Command { func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
opts := pruneOptions{filter: opts.NewFilterOpt()} options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "prune [OPTIONS]", Use: "prune [OPTIONS]",
Short: "Remove all stopped containers", Short: "Remove all stopped containers",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
spaceReclaimed, output, err := runPrune(dockerCli, opts) spaceReclaimed, output, err := runPrune(dockerCli, options)
if err != nil { if err != nil {
return err return err
} }
@ -39,8 +39,8 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
flags.Var(&opts.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')") flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')")
return cmd return cmd
} }
@ -48,10 +48,10 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
const warning = `WARNING! This will remove all stopped containers. const warning = `WARNING! This will remove all stopped containers.
Are you sure you want to continue?` Are you sure you want to continue?`
func runPrune(dockerCli command.Cli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
pruneFilters := command.PruneFilters(dockerCli, opts.filter.Value()) pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
return return
} }

View File

@ -3,7 +3,7 @@ package container
import ( import (
"testing" "testing"
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -6,8 +6,8 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
containertypes "github.com/docker/docker/api/types/container" containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -37,71 +37,71 @@ type updateOptions struct {
// NewUpdateCommand creates a new cobra.Command for `docker update` // NewUpdateCommand creates a new cobra.Command for `docker update`
func NewUpdateCommand(dockerCli *command.DockerCli) *cobra.Command { func NewUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
var opts updateOptions var options updateOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "update [OPTIONS] CONTAINER [CONTAINER...]", Use: "update [OPTIONS] CONTAINER [CONTAINER...]",
Short: "Update configuration of one or more containers", Short: "Update configuration of one or more containers",
Args: cli.RequiresMinArgs(1), Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args options.containers = args
opts.nFlag = cmd.Flags().NFlag() options.nFlag = cmd.Flags().NFlag()
return runUpdate(dockerCli, &opts) return runUpdate(dockerCli, &options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.Uint16Var(&opts.blkioWeight, "blkio-weight", 0, "Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)") flags.Uint16Var(&options.blkioWeight, "blkio-weight", 0, "Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)")
flags.Int64Var(&opts.cpuPeriod, "cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period") flags.Int64Var(&options.cpuPeriod, "cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period")
flags.Int64Var(&opts.cpuQuota, "cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota") flags.Int64Var(&options.cpuQuota, "cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota")
flags.Int64Var(&opts.cpuRealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds") flags.Int64Var(&options.cpuRealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds")
flags.SetAnnotation("cpu-rt-period", "version", []string{"1.25"}) flags.SetAnnotation("cpu-rt-period", "version", []string{"1.25"})
flags.Int64Var(&opts.cpuRealtimeRuntime, "cpu-rt-runtime", 0, "Limit the CPU real-time runtime in microseconds") flags.Int64Var(&options.cpuRealtimeRuntime, "cpu-rt-runtime", 0, "Limit the CPU real-time runtime in microseconds")
flags.SetAnnotation("cpu-rt-runtime", "version", []string{"1.25"}) flags.SetAnnotation("cpu-rt-runtime", "version", []string{"1.25"})
flags.StringVar(&opts.cpusetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)") flags.StringVar(&options.cpusetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)")
flags.StringVar(&opts.cpusetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)") flags.StringVar(&options.cpusetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)")
flags.Int64VarP(&opts.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)") flags.Int64VarP(&options.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)")
flags.VarP(&opts.memory, "memory", "m", "Memory limit") flags.VarP(&options.memory, "memory", "m", "Memory limit")
flags.Var(&opts.memoryReservation, "memory-reservation", "Memory soft limit") flags.Var(&options.memoryReservation, "memory-reservation", "Memory soft limit")
flags.Var(&opts.memorySwap, "memory-swap", "Swap limit equal to memory plus swap: '-1' to enable unlimited swap") flags.Var(&options.memorySwap, "memory-swap", "Swap limit equal to memory plus swap: '-1' to enable unlimited swap")
flags.Var(&opts.kernelMemory, "kernel-memory", "Kernel memory limit") flags.Var(&options.kernelMemory, "kernel-memory", "Kernel memory limit")
flags.StringVar(&opts.restartPolicy, "restart", "", "Restart policy to apply when a container exits") flags.StringVar(&options.restartPolicy, "restart", "", "Restart policy to apply when a container exits")
flags.Var(&opts.cpus, "cpus", "Number of CPUs") flags.Var(&options.cpus, "cpus", "Number of CPUs")
flags.SetAnnotation("cpus", "version", []string{"1.29"}) flags.SetAnnotation("cpus", "version", []string{"1.29"})
return cmd return cmd
} }
func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error { func runUpdate(dockerCli *command.DockerCli, options *updateOptions) error {
var err error var err error
if opts.nFlag == 0 { if options.nFlag == 0 {
return errors.New("you must provide one or more flags when using this command") return errors.New("you must provide one or more flags when using this command")
} }
var restartPolicy containertypes.RestartPolicy var restartPolicy containertypes.RestartPolicy
if opts.restartPolicy != "" { if options.restartPolicy != "" {
restartPolicy, err = runconfigopts.ParseRestartPolicy(opts.restartPolicy) restartPolicy, err = runconfigopts.ParseRestartPolicy(options.restartPolicy)
if err != nil { if err != nil {
return err return err
} }
} }
resources := containertypes.Resources{ resources := containertypes.Resources{
BlkioWeight: opts.blkioWeight, BlkioWeight: options.blkioWeight,
CpusetCpus: opts.cpusetCpus, CpusetCpus: options.cpusetCpus,
CpusetMems: opts.cpusetMems, CpusetMems: options.cpusetMems,
CPUShares: opts.cpuShares, CPUShares: options.cpuShares,
Memory: opts.memory.Value(), Memory: options.memory.Value(),
MemoryReservation: opts.memoryReservation.Value(), MemoryReservation: options.memoryReservation.Value(),
MemorySwap: opts.memorySwap.Value(), MemorySwap: options.memorySwap.Value(),
KernelMemory: opts.kernelMemory.Value(), KernelMemory: options.kernelMemory.Value(),
CPUPeriod: opts.cpuPeriod, CPUPeriod: options.cpuPeriod,
CPUQuota: opts.cpuQuota, CPUQuota: options.cpuQuota,
CPURealtimePeriod: opts.cpuRealtimePeriod, CPURealtimePeriod: options.cpuRealtimePeriod,
CPURealtimeRuntime: opts.cpuRealtimeRuntime, CPURealtimeRuntime: options.cpuRealtimeRuntime,
NanoCPUs: opts.cpus.Value(), NanoCPUs: options.cpus.Value(),
} }
updateConfig := containertypes.UpdateConfig{ updateConfig := containertypes.UpdateConfig{
@ -115,7 +115,7 @@ func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error {
warns []string warns []string
errs []string errs []string
) )
for _, container := range opts.containers { for _, container := range options.containers {
r, err := dockerCli.Client().ContainerUpdate(ctx, container, updateConfig) r, err := dockerCli.Client().ContainerUpdate(ctx, container, updateConfig)
if err != nil { if err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())

View File

@ -15,11 +15,11 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/image/build" "github.com/docker/cli/cli/command/image/build"
"github.com/docker/cli/opts"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
"github.com/docker/docker/api" "github.com/docker/docker/api"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/progress" "github.com/docker/docker/pkg/progress"

View File

@ -4,15 +4,14 @@ import (
"io" "io"
"os" "os"
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
dockeropts "github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
dockeropts "github.com/docker/docker/opts"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/urlutil" "github.com/docker/docker/pkg/urlutil"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type importOptions struct { type importOptions struct {
@ -24,41 +23,41 @@ type importOptions struct {
// NewImportCommand creates a new `docker import` command // NewImportCommand creates a new `docker import` command
func NewImportCommand(dockerCli command.Cli) *cobra.Command { func NewImportCommand(dockerCli command.Cli) *cobra.Command {
var opts importOptions var options importOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]", Use: "import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]",
Short: "Import the contents from a tarball to create a filesystem image", Short: "Import the contents from a tarball to create a filesystem image",
Args: cli.RequiresMinArgs(1), Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
opts.source = args[0] options.source = args[0]
if len(args) > 1 { if len(args) > 1 {
opts.reference = args[1] options.reference = args[1]
} }
return runImport(dockerCli, opts) return runImport(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
opts.changes = dockeropts.NewListOpts(nil) options.changes = dockeropts.NewListOpts(nil)
flags.VarP(&opts.changes, "change", "c", "Apply Dockerfile instruction to the created image") flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image")
flags.StringVarP(&opts.message, "message", "m", "", "Set commit message for imported image") flags.StringVarP(&options.message, "message", "m", "", "Set commit message for imported image")
return cmd return cmd
} }
func runImport(dockerCli command.Cli, opts importOptions) error { func runImport(dockerCli command.Cli, options importOptions) error {
var ( var (
in io.Reader in io.Reader
srcName = opts.source srcName = options.source
) )
if opts.source == "-" { if options.source == "-" {
in = dockerCli.In() in = dockerCli.In()
} else if !urlutil.IsURL(opts.source) { } else if !urlutil.IsURL(options.source) {
srcName = "-" srcName = "-"
file, err := os.Open(opts.source) file, err := os.Open(options.source)
if err != nil { if err != nil {
return err return err
} }
@ -71,14 +70,14 @@ func runImport(dockerCli command.Cli, opts importOptions) error {
SourceName: srcName, SourceName: srcName,
} }
options := types.ImageImportOptions{ importOptions := types.ImageImportOptions{
Message: opts.message, Message: options.message,
Changes: opts.changes.GetAll(), Changes: options.changes.GetAll(),
} }
clnt := dockerCli.Client() clnt := dockerCli.Client()
responseBody, err := clnt.ImageImport(context.Background(), source, opts.reference, options) responseBody, err := clnt.ImageImport(context.Background(), source, options.reference, importOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,14 +1,13 @@
package image package image
import ( import (
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type imagesOptions struct { type imagesOptions struct {
@ -24,7 +23,7 @@ type imagesOptions struct {
// NewImagesCommand creates a new `docker images` command // NewImagesCommand creates a new `docker images` command
func NewImagesCommand(dockerCli command.Cli) *cobra.Command { func NewImagesCommand(dockerCli command.Cli) *cobra.Command {
opts := imagesOptions{filter: opts.NewFilterOpt()} options := imagesOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "images [OPTIONS] [REPOSITORY[:TAG]]", Use: "images [OPTIONS] [REPOSITORY[:TAG]]",
@ -32,20 +31,20 @@ func NewImagesCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.RequiresMaxArgs(1), Args: cli.RequiresMaxArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 { if len(args) > 0 {
opts.matchName = args[0] options.matchName = args[0]
} }
return runImages(dockerCli, opts) return runImages(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only show numeric IDs") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only show numeric IDs")
flags.BoolVarP(&opts.all, "all", "a", false, "Show all images (default hides intermediate images)") flags.BoolVarP(&options.all, "all", "a", false, "Show all images (default hides intermediate images)")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output")
flags.BoolVar(&opts.showDigests, "digests", false, "Show digests") flags.BoolVar(&options.showDigests, "digests", false, "Show digests")
flags.StringVar(&opts.format, "format", "", "Pretty-print images using a Go template") flags.StringVar(&options.format, "format", "", "Pretty-print images using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
return cmd return cmd
} }
@ -57,27 +56,27 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
return &cmd return &cmd
} }
func runImages(dockerCli command.Cli, opts imagesOptions) error { func runImages(dockerCli command.Cli, options imagesOptions) error {
ctx := context.Background() ctx := context.Background()
filters := opts.filter.Value() filters := options.filter.Value()
if opts.matchName != "" { if options.matchName != "" {
filters.Add("reference", opts.matchName) filters.Add("reference", options.matchName)
} }
options := types.ImageListOptions{ listOptions := types.ImageListOptions{
All: opts.all, All: options.all,
Filters: filters, Filters: filters,
} }
images, err := dockerCli.Client().ImageList(ctx, options) images, err := dockerCli.Client().ImageList(ctx, listOptions)
if err != nil { if err != nil {
return err return err
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().ImagesFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().ImagesFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().ImagesFormat format = dockerCli.ConfigFile().ImagesFormat
} else { } else {
format = formatter.TableFormatKey format = formatter.TableFormatKey
@ -87,10 +86,10 @@ func runImages(dockerCli command.Cli, opts imagesOptions) error {
imageCtx := formatter.ImageContext{ imageCtx := formatter.ImageContext{
Context: formatter.Context{ Context: formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: formatter.NewImageFormat(format, opts.quiet, opts.showDigests), Format: formatter.NewImageFormat(format, options.quiet, options.showDigests),
Trunc: !opts.noTrunc, Trunc: !options.noTrunc,
}, },
Digest: opts.showDigests, Digest: options.showDigests,
} }
return formatter.ImageWrite(imageCtx, images) return formatter.ImageWrite(imageCtx, images)
} }

View File

@ -7,7 +7,7 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
units "github.com/docker/go-units" units "github.com/docker/go-units"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -20,14 +20,14 @@ type pruneOptions struct {
// NewPruneCommand returns a new cobra prune command for images // NewPruneCommand returns a new cobra prune command for images
func NewPruneCommand(dockerCli command.Cli) *cobra.Command { func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
opts := pruneOptions{filter: opts.NewFilterOpt()} options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "prune [OPTIONS]", Use: "prune [OPTIONS]",
Short: "Remove unused images", Short: "Remove unused images",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
spaceReclaimed, output, err := runPrune(dockerCli, opts) spaceReclaimed, output, err := runPrune(dockerCli, options)
if err != nil { if err != nil {
return err return err
} }
@ -41,9 +41,9 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
flags.BoolVarP(&opts.all, "all", "a", false, "Remove all unused images, not just dangling ones") flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused images, not just dangling ones")
flags.Var(&opts.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')") flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')")
return cmd return cmd
} }
@ -55,16 +55,16 @@ Are you sure you want to continue?`
Are you sure you want to continue?` Are you sure you want to continue?`
) )
func runPrune(dockerCli command.Cli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
pruneFilters := opts.filter.Value() pruneFilters := options.filter.Value()
pruneFilters.Add("dangling", fmt.Sprintf("%v", !opts.all)) pruneFilters.Add("dangling", fmt.Sprintf("%v", !options.all))
pruneFilters = command.PruneFilters(dockerCli, pruneFilters) pruneFilters = command.PruneFilters(dockerCli, pruneFilters)
warning := danglingWarning warning := danglingWarning
if opts.all { if options.all {
warning = allImageWarning warning = allImageWarning
} }
if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
return return
} }

View File

@ -1,13 +1,12 @@
package network package network
import ( import (
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
"github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type connectOptions struct { type connectOptions struct {
@ -21,7 +20,7 @@ type connectOptions struct {
} }
func newConnectCommand(dockerCli *command.DockerCli) *cobra.Command { func newConnectCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := connectOptions{ options := connectOptions{
links: opts.NewListOpts(opts.ValidateLink), links: opts.NewListOpts(opts.ValidateLink),
} }
@ -30,34 +29,34 @@ func newConnectCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Connect a container to a network", Short: "Connect a container to a network",
Args: cli.ExactArgs(2), Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
opts.network = args[0] options.network = args[0]
opts.container = args[1] options.container = args[1]
return runConnect(dockerCli, opts) return runConnect(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.StringVar(&opts.ipaddress, "ip", "", "IPv4 address (e.g., 172.30.100.104)") flags.StringVar(&options.ipaddress, "ip", "", "IPv4 address (e.g., 172.30.100.104)")
flags.StringVar(&opts.ipv6address, "ip6", "", "IPv6 address (e.g., 2001:db8::33)") flags.StringVar(&options.ipv6address, "ip6", "", "IPv6 address (e.g., 2001:db8::33)")
flags.Var(&opts.links, "link", "Add link to another container") flags.Var(&options.links, "link", "Add link to another container")
flags.StringSliceVar(&opts.aliases, "alias", []string{}, "Add network-scoped alias for the container") flags.StringSliceVar(&options.aliases, "alias", []string{}, "Add network-scoped alias for the container")
flags.StringSliceVar(&opts.linklocalips, "link-local-ip", []string{}, "Add a link-local address for the container") flags.StringSliceVar(&options.linklocalips, "link-local-ip", []string{}, "Add a link-local address for the container")
return cmd return cmd
} }
func runConnect(dockerCli *command.DockerCli, opts connectOptions) error { func runConnect(dockerCli *command.DockerCli, options connectOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
epConfig := &network.EndpointSettings{ epConfig := &network.EndpointSettings{
IPAMConfig: &network.EndpointIPAMConfig{ IPAMConfig: &network.EndpointIPAMConfig{
IPv4Address: opts.ipaddress, IPv4Address: options.ipaddress,
IPv6Address: opts.ipv6address, IPv6Address: options.ipv6address,
LinkLocalIPs: opts.linklocalips, LinkLocalIPs: options.linklocalips,
}, },
Links: opts.links.GetAll(), Links: options.links.GetAll(),
Aliases: opts.aliases, Aliases: options.aliases,
} }
return client.NetworkConnect(context.Background(), opts.network, opts.container, epConfig) return client.NetworkConnect(context.Background(), options.network, options.container, epConfig)
} }

View File

@ -5,16 +5,15 @@ import (
"net" "net"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type createOptions struct { type createOptions struct {
@ -36,7 +35,7 @@ type createOptions struct {
} }
func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := createOptions{ options := createOptions{
driverOpts: *opts.NewMapOpts(nil, nil), driverOpts: *opts.NewMapOpts(nil, nil),
labels: opts.NewListOpts(opts.ValidateEnv), labels: opts.NewListOpts(opts.ValidateEnv),
ipamAux: *opts.NewMapOpts(nil, nil), ipamAux: *opts.NewMapOpts(nil, nil),
@ -48,59 +47,59 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Create a network", Short: "Create a network",
Args: cli.ExactArgs(1), Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
opts.name = args[0] options.name = args[0]
return runCreate(dockerCli, opts) return runCreate(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.StringVarP(&opts.driver, "driver", "d", "bridge", "Driver to manage the Network") flags.StringVarP(&options.driver, "driver", "d", "bridge", "Driver to manage the Network")
flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options") flags.VarP(&options.driverOpts, "opt", "o", "Set driver specific options")
flags.Var(&opts.labels, "label", "Set metadata on a network") flags.Var(&options.labels, "label", "Set metadata on a network")
flags.BoolVar(&opts.internal, "internal", false, "Restrict external access to the network") flags.BoolVar(&options.internal, "internal", false, "Restrict external access to the network")
flags.BoolVar(&opts.ipv6, "ipv6", false, "Enable IPv6 networking") flags.BoolVar(&options.ipv6, "ipv6", false, "Enable IPv6 networking")
flags.BoolVar(&opts.attachable, "attachable", false, "Enable manual container attachment") flags.BoolVar(&options.attachable, "attachable", false, "Enable manual container attachment")
flags.SetAnnotation("attachable", "version", []string{"1.25"}) flags.SetAnnotation("attachable", "version", []string{"1.25"})
flags.BoolVar(&opts.ingress, "ingress", false, "Create swarm routing-mesh network") flags.BoolVar(&options.ingress, "ingress", false, "Create swarm routing-mesh network")
flags.SetAnnotation("ingress", "version", []string{"1.29"}) flags.SetAnnotation("ingress", "version", []string{"1.29"})
flags.StringVar(&opts.ipamDriver, "ipam-driver", "default", "IP Address Management Driver") flags.StringVar(&options.ipamDriver, "ipam-driver", "default", "IP Address Management Driver")
flags.StringSliceVar(&opts.ipamSubnet, "subnet", []string{}, "Subnet in CIDR format that represents a network segment") flags.StringSliceVar(&options.ipamSubnet, "subnet", []string{}, "Subnet in CIDR format that represents a network segment")
flags.StringSliceVar(&opts.ipamIPRange, "ip-range", []string{}, "Allocate container ip from a sub-range") flags.StringSliceVar(&options.ipamIPRange, "ip-range", []string{}, "Allocate container ip from a sub-range")
flags.StringSliceVar(&opts.ipamGateway, "gateway", []string{}, "IPv4 or IPv6 Gateway for the master subnet") flags.StringSliceVar(&options.ipamGateway, "gateway", []string{}, "IPv4 or IPv6 Gateway for the master subnet")
flags.Var(&opts.ipamAux, "aux-address", "Auxiliary IPv4 or IPv6 addresses used by Network driver") flags.Var(&options.ipamAux, "aux-address", "Auxiliary IPv4 or IPv6 addresses used by Network driver")
flags.Var(&opts.ipamOpt, "ipam-opt", "Set IPAM driver specific options") flags.Var(&options.ipamOpt, "ipam-opt", "Set IPAM driver specific options")
return cmd return cmd
} }
func runCreate(dockerCli *command.DockerCli, opts createOptions) error { func runCreate(dockerCli *command.DockerCli, options createOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
ipamCfg, err := consolidateIpam(opts.ipamSubnet, opts.ipamIPRange, opts.ipamGateway, opts.ipamAux.GetAll()) ipamCfg, err := consolidateIpam(options.ipamSubnet, options.ipamIPRange, options.ipamGateway, options.ipamAux.GetAll())
if err != nil { if err != nil {
return err return err
} }
// Construct network create request body // Construct network create request body
nc := types.NetworkCreate{ nc := types.NetworkCreate{
Driver: opts.driver, Driver: options.driver,
Options: opts.driverOpts.GetAll(), Options: options.driverOpts.GetAll(),
IPAM: &network.IPAM{ IPAM: &network.IPAM{
Driver: opts.ipamDriver, Driver: options.ipamDriver,
Config: ipamCfg, Config: ipamCfg,
Options: opts.ipamOpt.GetAll(), Options: options.ipamOpt.GetAll(),
}, },
CheckDuplicate: true, CheckDuplicate: true,
Internal: opts.internal, Internal: options.internal,
EnableIPv6: opts.ipv6, EnableIPv6: options.ipv6,
Attachable: opts.attachable, Attachable: options.attachable,
Ingress: opts.ingress, Ingress: options.ingress,
Labels: runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()), Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
} }
resp, err := client.NetworkCreate(context.Background(), opts.name, nc) resp, err := client.NetworkCreate(context.Background(), options.name, nc)
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,14 +3,13 @@ package network
import ( import (
"sort" "sort"
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type byNetworkName []types.NetworkResource type byNetworkName []types.NetworkResource
@ -27,7 +26,7 @@ type listOptions struct {
} }
func newListCommand(dockerCli *command.DockerCli) *cobra.Command { func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := listOptions{filter: opts.NewFilterOpt()} options := listOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ls [OPTIONS]", Use: "ls [OPTIONS]",
@ -35,30 +34,30 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "List networks", Short: "List networks",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runList(dockerCli, opts) return runList(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display network IDs") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display network IDs")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate the output") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Do not truncate the output")
flags.StringVar(&opts.format, "format", "", "Pretty-print networks using a Go template") flags.StringVar(&options.format, "format", "", "Pretty-print networks using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Provide filter values (e.g. 'driver=bridge')") flags.VarP(&options.filter, "filter", "f", "Provide filter values (e.g. 'driver=bridge')")
return cmd return cmd
} }
func runList(dockerCli *command.DockerCli, opts listOptions) error { func runList(dockerCli *command.DockerCli, options listOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
options := types.NetworkListOptions{Filters: opts.filter.Value()} listOptions := types.NetworkListOptions{Filters: options.filter.Value()}
networkResources, err := client.NetworkList(context.Background(), options) networkResources, err := client.NetworkList(context.Background(), listOptions)
if err != nil { if err != nil {
return err return err
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().NetworksFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().NetworksFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().NetworksFormat format = dockerCli.ConfigFile().NetworksFormat
} else { } else {
format = formatter.TableFormatKey format = formatter.TableFormatKey
@ -69,8 +68,8 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
networksCtx := formatter.Context{ networksCtx := formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: formatter.NewNetworkFormat(format, opts.quiet), Format: formatter.NewNetworkFormat(format, options.quiet),
Trunc: !opts.noTrunc, Trunc: !options.noTrunc,
} }
return formatter.NetworkWrite(networksCtx, networkResources) return formatter.NetworkWrite(networksCtx, networkResources)
} }

View File

@ -3,12 +3,11 @@ package network
import ( import (
"fmt" "fmt"
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type pruneOptions struct { type pruneOptions struct {
@ -18,14 +17,14 @@ type pruneOptions struct {
// NewPruneCommand returns a new cobra prune command for networks // NewPruneCommand returns a new cobra prune command for networks
func NewPruneCommand(dockerCli command.Cli) *cobra.Command { func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
opts := pruneOptions{filter: opts.NewFilterOpt()} options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "prune [OPTIONS]", Use: "prune [OPTIONS]",
Short: "Remove all unused networks", Short: "Remove all unused networks",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
output, err := runPrune(dockerCli, opts) output, err := runPrune(dockerCli, options)
if err != nil { if err != nil {
return err return err
} }
@ -38,8 +37,8 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
flags.Var(&opts.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')") flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')")
return cmd return cmd
} }
@ -47,10 +46,10 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
const warning = `WARNING! This will remove all networks not used by at least one container. const warning = `WARNING! This will remove all networks not used by at least one container.
Are you sure you want to continue?` Are you sure you want to continue?`
func runPrune(dockerCli command.Cli, opts pruneOptions) (output string, err error) { func runPrune(dockerCli command.Cli, options pruneOptions) (output string, err error) {
pruneFilters := command.PruneFilters(dockerCli, opts.filter.Value()) pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
return return
} }

View File

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

View File

@ -1,7 +1,7 @@
package node package node
import ( import (
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
) )
type nodeOptions struct { type nodeOptions struct {

View File

@ -8,9 +8,9 @@ import (
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/command/idresolver" "github.com/docker/cli/cli/command/idresolver"
"github.com/docker/cli/cli/command/task" "github.com/docker/cli/cli/command/task"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/opts"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -26,33 +26,33 @@ type psOptions struct {
} }
func newPsCommand(dockerCli command.Cli) *cobra.Command { func newPsCommand(dockerCli command.Cli) *cobra.Command {
opts := psOptions{filter: opts.NewFilterOpt()} options := psOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ps [OPTIONS] [NODE...]", Use: "ps [OPTIONS] [NODE...]",
Short: "List tasks running on one or more nodes, defaults to current node", Short: "List tasks running on one or more nodes, defaults to current node",
Args: cli.RequiresMinArgs(0), Args: cli.RequiresMinArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
opts.nodeIDs = []string{"self"} options.nodeIDs = []string{"self"}
if len(args) != 0 { if len(args) != 0 {
opts.nodeIDs = args options.nodeIDs = args
} }
return runPs(dockerCli, opts) return runPs(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") flags.BoolVar(&options.noResolve, "no-resolve", false, "Do not map IDs to Names")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
flags.StringVar(&opts.format, "format", "", "Pretty-print tasks using a Go template") flags.StringVar(&options.format, "format", "", "Pretty-print tasks using a Go template")
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display task IDs") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display task IDs")
return cmd return cmd
} }
func runPs(dockerCli command.Cli, opts psOptions) error { func runPs(dockerCli command.Cli, options psOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
@ -61,7 +61,7 @@ func runPs(dockerCli command.Cli, opts psOptions) error {
tasks []swarm.Task tasks []swarm.Task
) )
for _, nodeID := range opts.nodeIDs { for _, nodeID := range options.nodeIDs {
nodeRef, err := Reference(ctx, client, nodeID) nodeRef, err := Reference(ctx, client, nodeID)
if err != nil { if err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
@ -74,7 +74,7 @@ func runPs(dockerCli command.Cli, opts psOptions) error {
continue continue
} }
filter := opts.filter.Value() filter := options.filter.Value()
filter.Add("node", node.ID) filter.Add("node", node.ID)
nodeTasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter}) nodeTasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter})
@ -86,9 +86,9 @@ func runPs(dockerCli command.Cli, opts psOptions) error {
tasks = append(tasks, nodeTasks...) tasks = append(tasks, nodeTasks...)
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if dockerCli.ConfigFile() != nil && len(dockerCli.ConfigFile().TasksFormat) > 0 && !opts.quiet { if dockerCli.ConfigFile() != nil && len(dockerCli.ConfigFile().TasksFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().TasksFormat format = dockerCli.ConfigFile().TasksFormat
} else { } else {
format = formatter.TableFormatKey format = formatter.TableFormatKey
@ -96,7 +96,7 @@ func runPs(dockerCli command.Cli, opts psOptions) error {
} }
if len(errs) == 0 || len(tasks) != 0 { if len(errs) == 0 || len(tasks) != 0 {
if err := task.Print(ctx, dockerCli, tasks, idresolver.New(client, opts.noResolve), !opts.noTrunc, opts.quiet, format); err != nil { if err := task.Print(ctx, dockerCli, tasks, idresolver.New(client, options.noResolve), !options.noTrunc, options.quiet, format); err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} }
} }

View File

@ -5,8 +5,8 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -19,7 +19,7 @@ var (
) )
func newUpdateCommand(dockerCli command.Cli) *cobra.Command { func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
nodeOpts := newNodeOptions() options := newNodeOptions()
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "update [OPTIONS] NODE", Use: "update [OPTIONS] NODE",
@ -31,9 +31,9 @@ func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.StringVar(&nodeOpts.role, flagRole, "", `Role of the node ("worker"|"manager")`) flags.StringVar(&options.role, flagRole, "", `Role of the node ("worker"|"manager")`)
flags.StringVar(&nodeOpts.availability, flagAvailability, "", `Availability of the node ("active"|"pause"|"drain")`) flags.StringVar(&options.availability, flagAvailability, "", `Availability of the node ("active"|"pause"|"drain")`)
flags.Var(&nodeOpts.annotations.labels, flagLabelAdd, "Add or update a node label (key=value)") flags.Var(&options.annotations.labels, flagLabelAdd, "Add or update a node label (key=value)")
labelKeys := opts.NewListOpts(nil) labelKeys := opts.NewListOpts(nil)
flags.Var(&labelKeys, flagLabelRemove, "Remove a node label if exists") flags.Var(&labelKeys, flagLabelRemove, "Remove a node label if exists")
return cmd return cmd

View File

@ -4,7 +4,7 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -17,7 +17,7 @@ type listOptions struct {
} }
func newListCommand(dockerCli *command.DockerCli) *cobra.Command { func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := listOptions{filter: opts.NewFilterOpt()} options := listOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ls [OPTIONS]", Use: "ls [OPTIONS]",
@ -25,29 +25,29 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
Aliases: []string{"list"}, Aliases: []string{"list"},
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runList(dockerCli, opts) return runList(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display plugin IDs") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display plugin IDs")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output")
flags.StringVar(&opts.format, "format", "", "Pretty-print plugins using a Go template") flags.StringVar(&options.format, "format", "", "Pretty-print plugins using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Provide filter values (e.g. 'enabled=true')") flags.VarP(&options.filter, "filter", "f", "Provide filter values (e.g. 'enabled=true')")
return cmd return cmd
} }
func runList(dockerCli *command.DockerCli, opts listOptions) error { func runList(dockerCli *command.DockerCli, options listOptions) error {
plugins, err := dockerCli.Client().PluginList(context.Background(), opts.filter.Value()) plugins, err := dockerCli.Client().PluginList(context.Background(), options.filter.Value())
if err != nil { if err != nil {
return err return err
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().PluginsFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().PluginsFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().PluginsFormat format = dockerCli.ConfigFile().PluginsFormat
} else { } else {
format = formatter.TableFormatKey format = formatter.TableFormatKey
@ -56,8 +56,8 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
pluginsCtx := formatter.Context{ pluginsCtx := formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: formatter.NewPluginFormat(format, opts.quiet), Format: formatter.NewPluginFormat(format, options.quiet),
Trunc: !opts.noTrunc, Trunc: !options.noTrunc,
} }
return formatter.PluginWrite(pluginsCtx, plugins) return formatter.PluginWrite(pluginsCtx, plugins)
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/docker/cli/cli/command/image" "github.com/docker/cli/cli/command/image"
"github.com/docker/cli/cli/command/network" "github.com/docker/cli/cli/command/network"
"github.com/docker/cli/cli/command/volume" "github.com/docker/cli/cli/command/volume"
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -6,16 +6,15 @@ import (
"strings" "strings"
"text/tabwriter" "text/tabwriter"
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry" registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/stringutils" "github.com/docker/docker/pkg/stringutils"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type searchOptions struct { type searchOptions struct {
@ -31,26 +30,26 @@ type searchOptions struct {
// NewSearchCommand creates a new `docker search` command // NewSearchCommand creates a new `docker search` command
func NewSearchCommand(dockerCli command.Cli) *cobra.Command { func NewSearchCommand(dockerCli command.Cli) *cobra.Command {
opts := searchOptions{filter: opts.NewFilterOpt()} options := searchOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "search [OPTIONS] TERM", Use: "search [OPTIONS] TERM",
Short: "Search the Docker Hub for images", Short: "Search the Docker Hub for images",
Args: cli.ExactArgs(1), Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
opts.term = args[0] options.term = args[0]
return runSearch(dockerCli, opts) return runSearch(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
flags.IntVar(&opts.limit, "limit", registry.DefaultSearchLimit, "Max number of search results") flags.IntVar(&options.limit, "limit", registry.DefaultSearchLimit, "Max number of search results")
flags.BoolVar(&opts.automated, "automated", false, "Only show automated builds") flags.BoolVar(&options.automated, "automated", false, "Only show automated builds")
flags.UintVarP(&opts.stars, "stars", "s", 0, "Only displays with at least x stars") flags.UintVarP(&options.stars, "stars", "s", 0, "Only displays with at least x stars")
flags.MarkDeprecated("automated", "use --filter=is-automated=true instead") flags.MarkDeprecated("automated", "use --filter=is-automated=true instead")
flags.MarkDeprecated("stars", "use --filter=stars=3 instead") flags.MarkDeprecated("stars", "use --filter=stars=3 instead")
@ -58,8 +57,8 @@ func NewSearchCommand(dockerCli command.Cli) *cobra.Command {
return cmd return cmd
} }
func runSearch(dockerCli command.Cli, opts searchOptions) error { func runSearch(dockerCli command.Cli, options searchOptions) error {
indexInfo, err := registry.ParseSearchIndexInfo(opts.term) indexInfo, err := registry.ParseSearchIndexInfo(options.term)
if err != nil { if err != nil {
return err return err
} }
@ -74,16 +73,16 @@ func runSearch(dockerCli command.Cli, opts searchOptions) error {
return err return err
} }
options := types.ImageSearchOptions{ searchOptions := types.ImageSearchOptions{
RegistryAuth: encodedAuth, RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege, PrivilegeFunc: requestPrivilege,
Filters: opts.filter.Value(), Filters: options.filter.Value(),
Limit: opts.limit, Limit: options.limit,
} }
clnt := dockerCli.Client() clnt := dockerCli.Client()
unorderedResults, err := clnt.ImageSearch(ctx, opts.term, options) unorderedResults, err := clnt.ImageSearch(ctx, options.term, searchOptions)
if err != nil { if err != nil {
return err return err
} }
@ -95,12 +94,12 @@ func runSearch(dockerCli command.Cli, opts searchOptions) error {
fmt.Fprintf(w, "NAME\tDESCRIPTION\tSTARS\tOFFICIAL\tAUTOMATED\n") fmt.Fprintf(w, "NAME\tDESCRIPTION\tSTARS\tOFFICIAL\tAUTOMATED\n")
for _, res := range results { for _, res := range results {
// --automated and -s, --stars are deprecated since Docker 1.12 // --automated and -s, --stars are deprecated since Docker 1.12
if (opts.automated && !res.IsAutomated) || (int(opts.stars) > res.StarCount) { if (options.automated && !res.IsAutomated) || (int(options.stars) > res.StarCount) {
continue continue
} }
desc := strings.Replace(res.Description, "\n", " ", -1) desc := strings.Replace(res.Description, "\n", " ", -1)
desc = strings.Replace(desc, "\r", " ", -1) desc = strings.Replace(desc, "\r", " ", -1)
if !opts.noTrunc { if !options.noTrunc {
desc = stringutils.Ellipsis(desc, 45) desc = stringutils.Ellipsis(desc, 45)
} }
fmt.Fprintf(w, "%s\t%s\t%d\t", res.Name, desc, res.StarCount) fmt.Fprintf(w, "%s\t%s\t%d\t", res.Name, desc, res.StarCount)

View File

@ -7,8 +7,8 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -23,7 +23,7 @@ type createOptions struct {
} }
func newSecretCreateCommand(dockerCli command.Cli) *cobra.Command { func newSecretCreateCommand(dockerCli command.Cli) *cobra.Command {
createOpts := createOptions{ options := createOptions{
labels: opts.NewListOpts(opts.ValidateEnv), labels: opts.NewListOpts(opts.ValidateEnv),
} }
@ -32,13 +32,13 @@ func newSecretCreateCommand(dockerCli command.Cli) *cobra.Command {
Short: "Create a secret from a file or STDIN as content", Short: "Create a secret from a file or STDIN as content",
Args: cli.ExactArgs(2), Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
createOpts.name = args[0] options.name = args[0]
createOpts.file = args[1] options.file = args[1]
return runSecretCreate(dockerCli, createOpts) return runSecretCreate(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.VarP(&createOpts.labels, "label", "l", "Secret labels") flags.VarP(&options.labels, "label", "l", "Secret labels")
return cmd return cmd
} }

View File

@ -4,8 +4,8 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -17,7 +17,7 @@ type listOptions struct {
} }
func newSecretListCommand(dockerCli command.Cli) *cobra.Command { func newSecretListCommand(dockerCli command.Cli) *cobra.Command {
opts := listOptions{filter: opts.NewFilterOpt()} options := listOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ls [OPTIONS]", Use: "ls [OPTIONS]",
@ -25,29 +25,29 @@ func newSecretListCommand(dockerCli command.Cli) *cobra.Command {
Short: "List secrets", Short: "List secrets",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runSecretList(dockerCli, opts) return runSecretList(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display IDs")
flags.StringVarP(&opts.format, "format", "", "", "Pretty-print secrets using a Go template") flags.StringVarP(&options.format, "format", "", "", "Pretty-print secrets using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
return cmd return cmd
} }
func runSecretList(dockerCli command.Cli, opts listOptions) error { func runSecretList(dockerCli command.Cli, options listOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
secrets, err := client.SecretList(ctx, types.SecretListOptions{Filters: opts.filter.Value()}) secrets, err := client.SecretList(ctx, types.SecretListOptions{Filters: options.filter.Value()})
if err != nil { if err != nil {
return err return err
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().SecretFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().SecretFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().SecretFormat format = dockerCli.ConfigFile().SecretFormat
} else { } else {
format = formatter.TableFormatKey format = formatter.TableFormatKey
@ -55,7 +55,7 @@ func runSecretList(dockerCli command.Cli, opts listOptions) error {
} }
secretCtx := formatter.Context{ secretCtx := formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: formatter.NewSecretFormat(format, opts.quiet), Format: formatter.NewSecretFormat(format, options.quiet),
} }
return formatter.SecretWrite(secretCtx, secrets) return formatter.SecretWrite(secretCtx, secrets)
} }

View File

@ -6,10 +6,10 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -21,7 +21,7 @@ type listOptions struct {
} }
func newListCommand(dockerCli *command.DockerCli) *cobra.Command { func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := listOptions{filter: opts.NewFilterOpt()} options := listOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ls [OPTIONS]", Use: "ls [OPTIONS]",
@ -29,30 +29,30 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "List services", Short: "List services",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runList(dockerCli, opts) return runList(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display IDs")
flags.StringVar(&opts.format, "format", "", "Pretty-print services using a Go template") flags.StringVar(&options.format, "format", "", "Pretty-print services using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
return cmd return cmd
} }
func runList(dockerCli *command.DockerCli, opts listOptions) error { func runList(dockerCli *command.DockerCli, options listOptions) error {
ctx := context.Background() ctx := context.Background()
client := dockerCli.Client() client := dockerCli.Client()
serviceFilters := opts.filter.Value() serviceFilters := options.filter.Value()
services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: serviceFilters}) services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: serviceFilters})
if err != nil { if err != nil {
return err return err
} }
info := map[string]formatter.ServiceListInfo{} info := map[string]formatter.ServiceListInfo{}
if len(services) > 0 && !opts.quiet { if len(services) > 0 && !options.quiet {
// only non-empty services and not quiet, should we call TaskList and NodeList api // only non-empty services and not quiet, should we call TaskList and NodeList api
taskFilter := filters.NewArgs() taskFilter := filters.NewArgs()
for _, service := range services { for _, service := range services {
@ -72,9 +72,9 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
info = GetServicesStatus(services, nodes, tasks) info = GetServicesStatus(services, nodes, tasks)
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().ServicesFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().ServicesFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().ServicesFormat format = dockerCli.ConfigFile().ServicesFormat
} else { } else {
format = formatter.TableFormatKey format = formatter.TableFormatKey
@ -83,7 +83,7 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
servicesCtx := formatter.Context{ servicesCtx := formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: formatter.NewServiceListFormat(format, opts.quiet), Format: formatter.NewServiceListFormat(format, options.quiet),
} }
return formatter.ServiceListWrite(servicesCtx, services, info) return formatter.ServiceListWrite(servicesCtx, services, info)
} }

View File

@ -7,10 +7,10 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/swarmkit/api" "github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/api/defaults" "github.com/docker/swarmkit/api/defaults"

View File

@ -4,8 +4,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/opts"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -3,19 +3,18 @@ package service
import ( import (
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/command/idresolver" "github.com/docker/cli/cli/command/idresolver"
"github.com/docker/cli/cli/command/node" "github.com/docker/cli/cli/command/node"
"github.com/docker/cli/cli/command/task" "github.com/docker/cli/cli/command/task"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/opts"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type psOptions struct { type psOptions struct {
@ -28,36 +27,36 @@ type psOptions struct {
} }
func newPsCommand(dockerCli command.Cli) *cobra.Command { func newPsCommand(dockerCli command.Cli) *cobra.Command {
opts := psOptions{filter: opts.NewFilterOpt()} options := psOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ps [OPTIONS] SERVICE [SERVICE...]", Use: "ps [OPTIONS] SERVICE [SERVICE...]",
Short: "List the tasks of one or more services", Short: "List the tasks of one or more services",
Args: cli.RequiresMinArgs(1), Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
opts.services = args options.services = args
return runPS(dockerCli, opts) return runPS(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display task IDs") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display task IDs")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") flags.BoolVar(&options.noResolve, "no-resolve", false, "Do not map IDs to Names")
flags.StringVar(&opts.format, "format", "", "Pretty-print tasks using a Go template") flags.StringVar(&options.format, "format", "", "Pretty-print tasks using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
return cmd return cmd
} }
func runPS(dockerCli command.Cli, opts psOptions) error { func runPS(dockerCli command.Cli, options psOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
filter := opts.filter.Value() filter := options.filter.Value()
serviceIDFilter := filters.NewArgs() serviceIDFilter := filters.NewArgs()
serviceNameFilter := filters.NewArgs() serviceNameFilter := filters.NewArgs()
for _, service := range opts.services { for _, service := range options.services {
serviceIDFilter.Add("id", service) serviceIDFilter.Add("id", service)
serviceNameFilter.Add("name", service) serviceNameFilter.Add("name", service)
} }
@ -70,7 +69,7 @@ func runPS(dockerCli command.Cli, opts psOptions) error {
return err return err
} }
for _, service := range opts.services { for _, service := range options.services {
serviceCount := 0 serviceCount := 0
// Lookup by ID/Prefix // Lookup by ID/Prefix
for _, serviceEntry := range serviceByIDList { for _, serviceEntry := range serviceByIDList {
@ -110,14 +109,14 @@ func runPS(dockerCli command.Cli, opts psOptions) error {
return err return err
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().TasksFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().TasksFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().TasksFormat format = dockerCli.ConfigFile().TasksFormat
} else { } else {
format = formatter.TableFormatKey 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)
} }

View File

@ -8,13 +8,13 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
mounttypes "github.com/docker/docker/api/types/mount" mounttypes "github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/swarmkit/api/defaults" "github.com/docker/swarmkit/api/defaults"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -24,14 +24,14 @@ import (
) )
func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command { func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
serviceOpts := newServiceOptions() options := newServiceOptions()
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "update [OPTIONS] SERVICE", Use: "update [OPTIONS] SERVICE",
Short: "Update a service", Short: "Update a service",
Args: cli.ExactArgs(1), Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runUpdate(dockerCli, cmd.Flags(), serviceOpts, args[0]) return runUpdate(dockerCli, cmd.Flags(), options, args[0])
}, },
} }
@ -42,7 +42,7 @@ func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
flags.SetAnnotation("rollback", "version", []string{"1.25"}) flags.SetAnnotation("rollback", "version", []string{"1.25"})
flags.Bool("force", false, "Force update even if no changes require it") flags.Bool("force", false, "Force update even if no changes require it")
flags.SetAnnotation("force", "version", []string{"1.25"}) flags.SetAnnotation("force", "version", []string{"1.25"})
addServiceFlags(flags, serviceOpts, nil) addServiceFlags(flags, options, nil)
flags.Var(newListOptsVar(), flagEnvRemove, "Remove an environment variable") flags.Var(newListOptsVar(), flagEnvRemove, "Remove an environment variable")
flags.Var(newListOptsVar(), flagGroupRemove, "Remove a previously added supplementary user group from the container") flags.Var(newListOptsVar(), flagGroupRemove, "Remove a previously added supplementary user group from the container")
@ -61,39 +61,39 @@ func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
flags.SetAnnotation(flagDNSSearchRemove, "version", []string{"1.25"}) flags.SetAnnotation(flagDNSSearchRemove, "version", []string{"1.25"})
flags.Var(newListOptsVar(), flagHostRemove, "Remove a custom host-to-IP mapping (host:ip)") flags.Var(newListOptsVar(), flagHostRemove, "Remove a custom host-to-IP mapping (host:ip)")
flags.SetAnnotation(flagHostRemove, "version", []string{"1.25"}) flags.SetAnnotation(flagHostRemove, "version", []string{"1.25"})
flags.Var(&serviceOpts.labels, flagLabelAdd, "Add or update a service label") flags.Var(&options.labels, flagLabelAdd, "Add or update a service label")
flags.Var(&serviceOpts.containerLabels, flagContainerLabelAdd, "Add or update a container label") flags.Var(&options.containerLabels, flagContainerLabelAdd, "Add or update a container label")
flags.Var(&serviceOpts.env, flagEnvAdd, "Add or update an environment variable") flags.Var(&options.env, flagEnvAdd, "Add or update an environment variable")
flags.Var(newListOptsVar(), flagSecretRemove, "Remove a secret") flags.Var(newListOptsVar(), flagSecretRemove, "Remove a secret")
flags.SetAnnotation(flagSecretRemove, "version", []string{"1.25"}) flags.SetAnnotation(flagSecretRemove, "version", []string{"1.25"})
flags.Var(&serviceOpts.secrets, flagSecretAdd, "Add or update a secret on a service") flags.Var(&options.secrets, flagSecretAdd, "Add or update a secret on a service")
flags.SetAnnotation(flagSecretAdd, "version", []string{"1.25"}) flags.SetAnnotation(flagSecretAdd, "version", []string{"1.25"})
flags.Var(newListOptsVar(), flagConfigRemove, "Remove a configuration file") flags.Var(newListOptsVar(), flagConfigRemove, "Remove a configuration file")
flags.SetAnnotation(flagConfigRemove, "version", []string{"1.30"}) flags.SetAnnotation(flagConfigRemove, "version", []string{"1.30"})
flags.Var(&serviceOpts.configs, flagConfigAdd, "Add or update a config file on a service") flags.Var(&options.configs, flagConfigAdd, "Add or update a config file on a service")
flags.SetAnnotation(flagConfigAdd, "version", []string{"1.30"}) flags.SetAnnotation(flagConfigAdd, "version", []string{"1.30"})
flags.Var(&serviceOpts.mounts, flagMountAdd, "Add or update a mount on a service") flags.Var(&options.mounts, flagMountAdd, "Add or update a mount on a service")
flags.Var(&serviceOpts.constraints, flagConstraintAdd, "Add or update a placement constraint") flags.Var(&options.constraints, flagConstraintAdd, "Add or update a placement constraint")
flags.Var(&serviceOpts.placementPrefs, flagPlacementPrefAdd, "Add a placement preference") flags.Var(&options.placementPrefs, flagPlacementPrefAdd, "Add a placement preference")
flags.SetAnnotation(flagPlacementPrefAdd, "version", []string{"1.28"}) flags.SetAnnotation(flagPlacementPrefAdd, "version", []string{"1.28"})
flags.Var(&placementPrefOpts{}, flagPlacementPrefRemove, "Remove a placement preference") flags.Var(&placementPrefOpts{}, flagPlacementPrefRemove, "Remove a placement preference")
flags.SetAnnotation(flagPlacementPrefRemove, "version", []string{"1.28"}) flags.SetAnnotation(flagPlacementPrefRemove, "version", []string{"1.28"})
flags.Var(&serviceOpts.networks, flagNetworkAdd, "Add a network") flags.Var(&options.networks, flagNetworkAdd, "Add a network")
flags.SetAnnotation(flagNetworkAdd, "version", []string{"1.29"}) flags.SetAnnotation(flagNetworkAdd, "version", []string{"1.29"})
flags.Var(newListOptsVar(), flagNetworkRemove, "Remove a network") flags.Var(newListOptsVar(), flagNetworkRemove, "Remove a network")
flags.SetAnnotation(flagNetworkRemove, "version", []string{"1.29"}) flags.SetAnnotation(flagNetworkRemove, "version", []string{"1.29"})
flags.Var(&serviceOpts.endpoint.publishPorts, flagPublishAdd, "Add or update a published port") flags.Var(&options.endpoint.publishPorts, flagPublishAdd, "Add or update a published port")
flags.Var(&serviceOpts.groups, flagGroupAdd, "Add an additional supplementary user group to the container") flags.Var(&options.groups, flagGroupAdd, "Add an additional supplementary user group to the container")
flags.SetAnnotation(flagGroupAdd, "version", []string{"1.25"}) flags.SetAnnotation(flagGroupAdd, "version", []string{"1.25"})
flags.Var(&serviceOpts.dns, flagDNSAdd, "Add or update a custom DNS server") flags.Var(&options.dns, flagDNSAdd, "Add or update a custom DNS server")
flags.SetAnnotation(flagDNSAdd, "version", []string{"1.25"}) flags.SetAnnotation(flagDNSAdd, "version", []string{"1.25"})
flags.Var(&serviceOpts.dnsOption, flagDNSOptionAdd, "Add or update a DNS option") flags.Var(&options.dnsOption, flagDNSOptionAdd, "Add or update a DNS option")
flags.SetAnnotation(flagDNSOptionAdd, "version", []string{"1.25"}) flags.SetAnnotation(flagDNSOptionAdd, "version", []string{"1.25"})
flags.Var(&serviceOpts.dnsSearch, flagDNSSearchAdd, "Add or update a custom DNS search domain") flags.Var(&options.dnsSearch, flagDNSSearchAdd, "Add or update a custom DNS search domain")
flags.SetAnnotation(flagDNSSearchAdd, "version", []string{"1.25"}) flags.SetAnnotation(flagDNSSearchAdd, "version", []string{"1.25"})
flags.Var(&serviceOpts.hosts, flagHostAdd, "Add or update a custom host-to-IP mapping (host:ip)") flags.Var(&options.hosts, flagHostAdd, "Add or update a custom host-to-IP mapping (host:ip)")
flags.SetAnnotation(flagHostAdd, "version", []string{"1.25"}) flags.SetAnnotation(flagHostAdd, "version", []string{"1.25"})
return cmd return cmd
@ -104,7 +104,7 @@ func newListOptsVar() *opts.ListOpts {
} }
// nolint: gocyclo // nolint: gocyclo
func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *serviceOptions, serviceID string) error { func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, options *serviceOptions, serviceID string) error {
apiClient := dockerCli.Client() apiClient := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
@ -214,7 +214,7 @@ func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *service
fmt.Fprintf(dockerCli.Out(), "%s\n", serviceID) fmt.Fprintf(dockerCli.Out(), "%s\n", serviceID)
if opts.detach { if options.detach {
if !flags.Changed("detach") { if !flags.Changed("detach") {
fmt.Fprintln(dockerCli.Err(), "Since --detach=false was not specified, tasks will be updated in the background.\n"+ fmt.Fprintln(dockerCli.Err(), "Since --detach=false was not specified, tasks will be updated in the background.\n"+
"In a future release, --detach=false will become the default.") "In a future release, --detach=false will become the default.")
@ -222,7 +222,7 @@ func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *service
return nil return nil
} }
return waitOnService(ctx, dockerCli, serviceID, opts) return waitOnService(ctx, dockerCli, serviceID, options)
} }
// nolint: gocyclo // nolint: gocyclo

View File

@ -1,14 +1,13 @@
package stack package stack
import ( import (
"golang.org/x/net/context"
"github.com/docker/cli/cli/compose/convert" "github.com/docker/cli/cli/compose/convert"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/opts" "golang.org/x/net/context"
) )
func getStackFilter(namespace string) filters.Args { func getStackFilter(namespace string) filters.Args {

View File

@ -3,16 +3,15 @@ package stack
import ( import (
"fmt" "fmt"
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/command/idresolver" "github.com/docker/cli/cli/command/idresolver"
"github.com/docker/cli/cli/command/task" "github.com/docker/cli/cli/command/task"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type psOptions struct { type psOptions struct {
@ -25,33 +24,33 @@ type psOptions struct {
} }
func newPsCommand(dockerCli command.Cli) *cobra.Command { func newPsCommand(dockerCli command.Cli) *cobra.Command {
opts := psOptions{filter: opts.NewFilterOpt()} options := psOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ps [OPTIONS] STACK", Use: "ps [OPTIONS] STACK",
Short: "List the tasks in the stack", Short: "List the tasks in the stack",
Args: cli.ExactArgs(1), Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
opts.namespace = args[0] options.namespace = args[0]
return runPS(dockerCli, opts) return runPS(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") flags.BoolVar(&options.noResolve, "no-resolve", false, "Do not map IDs to Names")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display task IDs") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display task IDs")
flags.StringVar(&opts.format, "format", "", "Pretty-print tasks using a Go template") flags.StringVar(&options.format, "format", "", "Pretty-print tasks using a Go template")
return cmd return cmd
} }
func runPS(dockerCli command.Cli, opts psOptions) error { func runPS(dockerCli command.Cli, options psOptions) error {
namespace := opts.namespace namespace := options.namespace
client := dockerCli.Client() client := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
filter := getStackFilterFromOpt(opts.namespace, opts.filter) filter := getStackFilterFromOpt(options.namespace, options.filter)
tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter}) tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter})
if err != nil { if err != nil {
@ -63,14 +62,14 @@ func runPS(dockerCli command.Cli, opts psOptions) error {
return nil return nil
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().TasksFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().TasksFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().TasksFormat format = dockerCli.ConfigFile().TasksFormat
} else { } else {
format = formatter.TableFormatKey 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)
} }

View File

@ -3,16 +3,15 @@ package stack
import ( import (
"fmt" "fmt"
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/command/service" "github.com/docker/cli/cli/command/service"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type servicesOptions struct { type servicesOptions struct {
@ -23,30 +22,30 @@ type servicesOptions struct {
} }
func newServicesCommand(dockerCli *command.DockerCli) *cobra.Command { func newServicesCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := servicesOptions{filter: opts.NewFilterOpt()} options := servicesOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "services [OPTIONS] STACK", Use: "services [OPTIONS] STACK",
Short: "List the services in the stack", Short: "List the services in the stack",
Args: cli.ExactArgs(1), Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
opts.namespace = args[0] options.namespace = args[0]
return runServices(dockerCli, opts) return runServices(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display IDs")
flags.StringVar(&opts.format, "format", "", "Pretty-print services using a Go template") flags.StringVar(&options.format, "format", "", "Pretty-print services using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
return cmd return cmd
} }
func runServices(dockerCli *command.DockerCli, opts servicesOptions) error { func runServices(dockerCli *command.DockerCli, options servicesOptions) error {
ctx := context.Background() ctx := context.Background()
client := dockerCli.Client() client := dockerCli.Client()
filter := getStackFilterFromOpt(opts.namespace, opts.filter) filter := getStackFilterFromOpt(options.namespace, options.filter)
services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: filter}) services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: filter})
if err != nil { if err != nil {
return err 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 no services in this stack, print message and exit 0
if len(services) == 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 return nil
} }
info := map[string]formatter.ServiceListInfo{} info := map[string]formatter.ServiceListInfo{}
if !opts.quiet { if !options.quiet {
taskFilter := filters.NewArgs() taskFilter := filters.NewArgs()
for _, service := range services { for _, service := range services {
taskFilter.Add("service", service.ID) taskFilter.Add("service", service.ID)
@ -80,9 +79,9 @@ func runServices(dockerCli *command.DockerCli, opts servicesOptions) error {
info = service.GetServicesStatus(services, nodes, tasks) info = service.GetServicesStatus(services, nodes, tasks)
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().ServicesFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().ServicesFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().ServicesFormat format = dockerCli.ConfigFile().ServicesFormat
} else { } else {
format = formatter.TableFormatKey format = formatter.TableFormatKey
@ -91,7 +90,7 @@ func runServices(dockerCli *command.DockerCli, opts servicesOptions) error {
servicesCtx := formatter.Context{ servicesCtx := formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: formatter.NewServiceListFormat(format, opts.quiet), Format: formatter.NewServiceListFormat(format, options.quiet),
} }
return formatter.ServiceListWrite(servicesCtx, services, info) return formatter.ServiceListWrite(servicesCtx, services, info)
} }

View File

@ -8,8 +8,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/opts"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )

View File

@ -9,16 +9,15 @@ import (
"text/template" "text/template"
"time" "time"
"golang.org/x/net/context"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
eventtypes "github.com/docker/docker/api/types/events" eventtypes "github.com/docker/docker/api/types/events"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/jsonlog" "github.com/docker/docker/pkg/jsonlog"
"github.com/docker/docker/pkg/templates" "github.com/docker/docker/pkg/templates"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type eventsOptions struct { type eventsOptions struct {
@ -30,41 +29,41 @@ type eventsOptions struct {
// NewEventsCommand creates a new cobra.Command for `docker events` // NewEventsCommand creates a new cobra.Command for `docker events`
func NewEventsCommand(dockerCli *command.DockerCli) *cobra.Command { func NewEventsCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := eventsOptions{filter: opts.NewFilterOpt()} options := eventsOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "events [OPTIONS]", Use: "events [OPTIONS]",
Short: "Get real time events from the server", Short: "Get real time events from the server",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runEvents(dockerCli, &opts) return runEvents(dockerCli, &options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.StringVar(&opts.since, "since", "", "Show all events created since timestamp") flags.StringVar(&options.since, "since", "", "Show all events created since timestamp")
flags.StringVar(&opts.until, "until", "", "Stream events until this timestamp") flags.StringVar(&options.until, "until", "", "Stream events until this timestamp")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
flags.StringVar(&opts.format, "format", "", "Format the output using the given Go template") flags.StringVar(&options.format, "format", "", "Format the output using the given Go template")
return cmd return cmd
} }
func runEvents(dockerCli *command.DockerCli, opts *eventsOptions) error { func runEvents(dockerCli *command.DockerCli, options *eventsOptions) error {
tmpl, err := makeTemplate(opts.format) tmpl, err := makeTemplate(options.format)
if err != nil { if err != nil {
return cli.StatusError{ return cli.StatusError{
StatusCode: 64, StatusCode: 64,
Status: "Error parsing format: " + err.Error()} Status: "Error parsing format: " + err.Error()}
} }
options := types.EventsOptions{ eventOptions := types.EventsOptions{
Since: opts.since, Since: options.since,
Until: opts.until, Until: options.until,
Filters: opts.filter.Value(), Filters: options.filter.Value(),
} }
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
events, errs := dockerCli.Client().Events(ctx, options) events, errs := dockerCli.Client().Events(ctx, eventOptions)
defer cancel() defer cancel()
out := dockerCli.Out() out := dockerCli.Out()

View File

@ -6,7 +6,7 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/prune" "github.com/docker/cli/cli/command/prune"
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
units "github.com/docker/go-units" units "github.com/docker/go-units"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -19,22 +19,22 @@ type pruneOptions struct {
// NewPruneCommand creates a new cobra.Command for `docker prune` // NewPruneCommand creates a new cobra.Command for `docker prune`
func NewPruneCommand(dockerCli command.Cli) *cobra.Command { func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
opts := pruneOptions{filter: opts.NewFilterOpt()} options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "prune [OPTIONS]", Use: "prune [OPTIONS]",
Short: "Remove unused data", Short: "Remove unused data",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runPrune(dockerCli, opts) return runPrune(dockerCli, options)
}, },
Tags: map[string]string{"version": "1.25"}, Tags: map[string]string{"version": "1.25"},
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
flags.BoolVarP(&opts.all, "all", "a", false, "Remove all unused images not just dangling ones") flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused images not just dangling ones")
flags.Var(&opts.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')") flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')")
return cmd return cmd
} }

View File

@ -5,8 +5,8 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
volumetypes "github.com/docker/docker/api/types/volume" volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -21,7 +21,7 @@ type createOptions struct {
} }
func newCreateCommand(dockerCli command.Cli) *cobra.Command { func newCreateCommand(dockerCli command.Cli) *cobra.Command {
opts := createOptions{ options := createOptions{
driverOpts: *opts.NewMapOpts(nil, nil), driverOpts: *opts.NewMapOpts(nil, nil),
labels: opts.NewListOpts(opts.ValidateEnv), labels: opts.NewListOpts(opts.ValidateEnv),
} }
@ -32,32 +32,32 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.RequiresMaxArgs(1), Args: cli.RequiresMaxArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 { if len(args) == 1 {
if opts.name != "" { if options.name != "" {
return errors.Errorf("Conflicting options: either specify --name or provide positional arg, not both\n") return errors.Errorf("Conflicting options: either specify --name or provide positional arg, not both\n")
} }
opts.name = args[0] options.name = args[0]
} }
return runCreate(dockerCli, opts) return runCreate(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.StringVarP(&opts.driver, "driver", "d", "local", "Specify volume driver name") flags.StringVarP(&options.driver, "driver", "d", "local", "Specify volume driver name")
flags.StringVar(&opts.name, "name", "", "Specify volume name") flags.StringVar(&options.name, "name", "", "Specify volume name")
flags.Lookup("name").Hidden = true flags.Lookup("name").Hidden = true
flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options") flags.VarP(&options.driverOpts, "opt", "o", "Set driver specific options")
flags.Var(&opts.labels, "label", "Set metadata for a volume") flags.Var(&options.labels, "label", "Set metadata for a volume")
return cmd return cmd
} }
func runCreate(dockerCli command.Cli, opts createOptions) error { func runCreate(dockerCli command.Cli, options createOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
volReq := volumetypes.VolumesCreateBody{ volReq := volumetypes.VolumesCreateBody{
Driver: opts.driver, Driver: options.driver,
DriverOpts: opts.driverOpts.GetAll(), DriverOpts: options.driverOpts.GetAll(),
Name: opts.name, Name: options.name,
Labels: runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()), Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
} }
vol, err := client.VolumeCreate(context.Background(), volReq) vol, err := client.VolumeCreate(context.Background(), volReq)

View File

@ -6,8 +6,8 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -27,7 +27,7 @@ type listOptions struct {
} }
func newListCommand(dockerCli command.Cli) *cobra.Command { func newListCommand(dockerCli command.Cli) *cobra.Command {
opts := listOptions{filter: opts.NewFilterOpt()} options := listOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ls [OPTIONS]", Use: "ls [OPTIONS]",
@ -35,28 +35,28 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
Short: "List volumes", Short: "List volumes",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runList(dockerCli, opts) return runList(dockerCli, options)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display volume names") flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display volume names")
flags.StringVar(&opts.format, "format", "", "Pretty-print volumes using a Go template") flags.StringVar(&options.format, "format", "", "Pretty-print volumes using a Go template")
flags.VarP(&opts.filter, "filter", "f", "Provide filter values (e.g. 'dangling=true')") flags.VarP(&options.filter, "filter", "f", "Provide filter values (e.g. 'dangling=true')")
return cmd return cmd
} }
func runList(dockerCli command.Cli, opts listOptions) error { func runList(dockerCli command.Cli, options listOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
volumes, err := client.VolumeList(context.Background(), opts.filter.Value()) volumes, err := client.VolumeList(context.Background(), options.filter.Value())
if err != nil { if err != nil {
return err return err
} }
format := opts.format format := options.format
if len(format) == 0 { if len(format) == 0 {
if len(dockerCli.ConfigFile().VolumesFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().VolumesFormat) > 0 && !options.quiet {
format = dockerCli.ConfigFile().VolumesFormat format = dockerCli.ConfigFile().VolumesFormat
} else { } else {
format = formatter.TableFormatKey format = formatter.TableFormatKey
@ -67,7 +67,7 @@ func runList(dockerCli command.Cli, opts listOptions) error {
volumeCtx := formatter.Context{ volumeCtx := formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: formatter.NewVolumeFormat(format, opts.quiet), Format: formatter.NewVolumeFormat(format, options.quiet),
} }
return formatter.VolumeWrite(volumeCtx, volumes.Volumes) return formatter.VolumeWrite(volumeCtx, volumes.Volumes)
} }

View File

@ -5,7 +5,7 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
units "github.com/docker/go-units" units "github.com/docker/go-units"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -18,14 +18,14 @@ type pruneOptions struct {
// NewPruneCommand returns a new cobra prune command for volumes // NewPruneCommand returns a new cobra prune command for volumes
func NewPruneCommand(dockerCli command.Cli) *cobra.Command { func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
opts := pruneOptions{filter: opts.NewFilterOpt()} options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "prune [OPTIONS]", Use: "prune [OPTIONS]",
Short: "Remove all unused volumes", Short: "Remove all unused volumes",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
spaceReclaimed, output, err := runPrune(dockerCli, opts) spaceReclaimed, output, err := runPrune(dockerCli, options)
if err != nil { if err != nil {
return err return err
} }
@ -39,8 +39,8 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
flags.Var(&opts.filter, "filter", "Provide filter values (e.g. 'label=<label>')") flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'label=<label>')")
return cmd return cmd
} }
@ -48,10 +48,10 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
const warning = `WARNING! This will remove all volumes not used by at least one container. const warning = `WARNING! This will remove all volumes not used by at least one container.
Are you sure you want to continue?` Are you sure you want to continue?`
func runPrune(dockerCli command.Cli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
pruneFilters := command.PruneFilters(dockerCli, opts.filter.Value()) pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
return return
} }

View File

@ -9,11 +9,11 @@ import (
servicecli "github.com/docker/cli/cli/command/service" servicecli "github.com/docker/cli/cli/command/service"
composetypes "github.com/docker/cli/cli/compose/types" composetypes "github.com/docker/cli/cli/compose/types"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/pkg/errors" "github.com/pkg/errors"
) )

View File

@ -12,7 +12,7 @@ import (
"github.com/docker/cli/cli/compose/schema" "github.com/docker/cli/cli/compose/schema"
"github.com/docker/cli/cli/compose/template" "github.com/docker/cli/cli/compose/template"
"github.com/docker/cli/cli/compose/types" "github.com/docker/cli/cli/compose/types"
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
units "github.com/docker/go-units" units "github.com/docker/go-units"

View File

@ -7,7 +7,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
cliconfig "github.com/docker/cli/cli/config" cliconfig "github.com/docker/cli/cli/config"
"github.com/docker/docker/opts" "github.com/docker/cli/opts"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )

View File

@ -17,6 +17,7 @@ type MountOpt struct {
} }
// Set a new mount value // Set a new mount value
// nolint: gocyclo
func (m *MountOpt) Set(value string) error { func (m *MountOpt) Set(value string) error {
csvReader := csv.NewReader(strings.NewReader(value)) csvReader := csv.NewReader(strings.NewReader(value))
fields, err := csvReader.Read() fields, err := csvReader.Read()

View File

@ -116,6 +116,7 @@ func TestListOptsWithValidator(t *testing.T) {
} }
} }
// nolint: lll
func TestValidateDNSSearch(t *testing.T) { func TestValidateDNSSearch(t *testing.T) {
valid := []string{ valid := []string{
`.`, `.`,

View File

@ -24,6 +24,7 @@ type PortOpt struct {
} }
// Set a new port value // Set a new port value
// nolint: gocyclo
func (p *PortOpt) Set(value string) error { func (p *PortOpt) Set(value string) error {
longSyntax, err := regexp.MatchString(`\w+=\w+(,\w+=\w+)*`, value) longSyntax, err := regexp.MatchString(`\w+=\w+(,\w+=\w+)*`, value)
if err != nil { if err != nil {
@ -101,7 +102,7 @@ func (p *PortOpt) Set(value string) error {
for _, portBindings := range portBindingMap { for _, portBindings := range portBindingMap {
for _, portBinding := range portBindings { for _, portBinding := range portBindings {
if portBinding.HostIP != "" { if portBinding.HostIP != "" {
return fmt.Errorf("HostIP is not supported.") return fmt.Errorf("hostip is not supported")
} }
} }
} }

View File

@ -273,7 +273,7 @@ func TestPortOptInvalidSimpleSyntax(t *testing.T) {
}, },
{ {
value: "1.1.1.1:80:80", value: "1.1.1.1:80:80",
expectedError: "HostIP is not supported.", expectedError: "hostip is not supported",
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {