Merge pull request #27 from dnephin/more-linters

More linters and better circle-ci config
This commit is contained in:
Daniel Nephin 2017-05-08 16:30:13 -04:00 committed by GitHub
commit d844c487d4
49 changed files with 203 additions and 114 deletions

View File

@ -34,5 +34,3 @@ vendor: vendor.conf
echo; git status --porcelain -- vendor 2>/dev/nul; \ echo; git status --porcelain -- vendor 2>/dev/nul; \
echo; exit 1; \ echo; exit 1; \
fi; fi;
ci: cross test

View File

@ -1,27 +1,41 @@
version: 2 version: 2
jobs: jobs:
build: build:
working_directory: ~/cli working_directory: /work
docker: docker:
- image: docker:17.05 - image: docker:17.05
parallelism: 4
steps: steps:
- run: - run:
name: "Install Git and SSH" name: "Install Git and SSH"
command: | command: apk add -U git openssh
apk add -U git openssh
- checkout - checkout
- setup_remote_docker - setup_remote_docker
- run: - run:
name: "Lint" name: "Lint"
command: | command: |
if [ "$CIRCLE_NODE_INDEX" != "0" ]; then exit; fi
docker build -f dockerfiles/Dockerfile.lint --tag cli-linter . docker build -f dockerfiles/Dockerfile.lint --tag cli-linter .
docker run cli-linter docker run cli-linter
- run: - run:
name: "Build and Unit Test" name: "Cross"
command: | command: |
if [ "$CIRCLE_NODE_INDEX" != "1" ]; then exit; fi
docker build -f dockerfiles/Dockerfile.ci --tag cli-builder . docker build -f dockerfiles/Dockerfile.ci --tag cli-builder .
docker run cli-builder docker run --name cross cli-builder make cross
docker cp cross:/go/src/github.com/docker/cli/build /work/build
- run:
name: "Unit Test"
command: |
if [ "$CIRCLE_NODE_INDEX" != "2" ]; then exit; fi
docker build -f dockerfiles/Dockerfile.ci --tag cli-builder .
docker run cli-builder make test
- run: - run:
name: "Vendor" name: "Vendor"
command: | command: |
docker run cli-builder make vendor if [ "$CIRCLE_NODE_INDEX" != "3" ]; then exit; fi
docker build -f dockerfiles/Dockerfile.ci --tag cli-builder .
docker run cli-builder make -B vendor
- store_artifacts:
path: /work/build

View File

@ -7,12 +7,12 @@ import (
) )
// NewCheckpointCommand returns the `checkpoint` subcommand (only in experimental) // NewCheckpointCommand returns the `checkpoint` subcommand (only in experimental)
func NewCheckpointCommand(dockerCli *command.DockerCli) *cobra.Command { func NewCheckpointCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "checkpoint", Use: "checkpoint",
Short: "Manage checkpoints", Short: "Manage checkpoints",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
Tags: map[string]string{"experimental": "", "version": "1.25"}, Tags: map[string]string{"experimental": "", "version": "1.25"},
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -18,7 +18,7 @@ type createOptions struct {
leaveRunning bool leaveRunning bool
} }
func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { func newCreateCommand(dockerCli command.Cli) *cobra.Command {
var opts createOptions var opts createOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -39,7 +39,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
func runCreate(dockerCli *command.DockerCli, opts createOptions) error { func runCreate(dockerCli command.Cli, opts createOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
checkpointOpts := types.CheckpointCreateOptions{ checkpointOpts := types.CheckpointCreateOptions{

View File

@ -14,7 +14,7 @@ type listOptions struct {
checkpointDir string checkpointDir string
} }
func newListCommand(dockerCli *command.DockerCli) *cobra.Command { func newListCommand(dockerCli command.Cli) *cobra.Command {
var opts listOptions var opts listOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -34,7 +34,7 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
} }
func runList(dockerCli *command.DockerCli, container string, opts listOptions) error { func runList(dockerCli command.Cli, container string, opts listOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
listOpts := types.CheckpointListOptions{ listOpts := types.CheckpointListOptions{

View File

@ -13,7 +13,7 @@ type removeOptions struct {
checkpointDir string checkpointDir string
} }
func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
var opts removeOptions var opts removeOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -32,7 +32,7 @@ func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
func runRemove(dockerCli *command.DockerCli, container string, checkpoint string, opts removeOptions) error { func runRemove(dockerCli command.Cli, container string, checkpoint string, opts removeOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
removeOpts := types.CheckpointDeleteOptions{ removeOpts := types.CheckpointDeleteOptions{

View File

@ -86,11 +86,13 @@ func (cli *DockerCli) In() *InStream {
} }
// ShowHelp shows the command help. // ShowHelp shows the command help.
func (cli *DockerCli) ShowHelp(cmd *cobra.Command, args []string) error { func ShowHelp(err io.Writer) func(*cobra.Command, []string) error {
cmd.SetOutput(cli.err) return func(cmd *cobra.Command, args []string) error {
cmd.SetOutput(err)
cmd.HelpFunc()(cmd, args) cmd.HelpFunc()(cmd, args)
return nil return nil
} }
}
// ConfigFile returns the ConfigFile // ConfigFile returns the ConfigFile
func (cli *DockerCli) ConfigFile() *configfile.ConfigFile { func (cli *DockerCli) ConfigFile() *configfile.ConfigFile {

View File

@ -7,12 +7,13 @@ import (
) )
// NewContainerCommand returns a cobra command for `container` subcommands // NewContainerCommand returns a cobra command for `container` subcommands
// nolint: interfacer
func NewContainerCommand(dockerCli *command.DockerCli) *cobra.Command { func NewContainerCommand(dockerCli *command.DockerCli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "container", Use: "container",
Short: "Manage containers", Short: "Manage containers",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
} }
cmd.AddCommand( cmd.AddCommand(
NewAttachCommand(dockerCli), NewAttachCommand(dockerCli),

View File

@ -25,7 +25,7 @@ type createOptions struct {
} }
// NewCreateCommand creates a new cobra.Command for `docker create` // NewCreateCommand creates a new cobra.Command for `docker create`
func NewCreateCommand(dockerCli *command.DockerCli) *cobra.Command { func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
var opts createOptions var opts createOptions
var copts *containerOptions var copts *containerOptions
@ -56,7 +56,7 @@ func NewCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
func runCreate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *createOptions, copts *containerOptions) error { func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, opts *createOptions, copts *containerOptions) error {
containerConfig, err := parse(flags, copts) containerConfig, err := parse(flags, copts)
if err != nil { if err != nil {
reportError(dockerCli.Err(), "create", err.Error(), true) reportError(dockerCli.Err(), "create", err.Error(), true)
@ -70,7 +70,7 @@ func runCreate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *createO
return nil return nil
} }
func pullImage(ctx context.Context, dockerCli *command.DockerCli, image string, out io.Writer) error { func pullImage(ctx context.Context, dockerCli command.Cli, image string, out io.Writer) error {
ref, err := reference.ParseNormalizedNamed(image) ref, err := reference.ParseNormalizedNamed(image)
if err != nil { if err != nil {
return err return err
@ -146,7 +146,7 @@ func newCIDFile(path string) (*cidFile, error) {
return &cidFile{path: path, file: f}, nil return &cidFile{path: path, file: f}, nil
} }
func createContainer(ctx context.Context, dockerCli *command.DockerCli, containerConfig *containerConfig, name string) (*container.ContainerCreateCreatedBody, error) { func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig *containerConfig, name string) (*container.ContainerCreateCreatedBody, error) {
config := containerConfig.Config config := containerConfig.Config
hostConfig := containerConfig.HostConfig hostConfig := containerConfig.HostConfig
networkingConfig := containerConfig.NetworkingConfig networkingConfig := containerConfig.NetworkingConfig

View File

@ -165,7 +165,9 @@ func TestParseRunVolumes(t *testing.T) {
// Two bind-mounts, first read-only, second read-write. // Two bind-mounts, first read-only, second read-write.
// TODO Windows: The Windows version uses read-write as that's the only mode it supports. Can change this post TP4 // TODO Windows: The Windows version uses read-write as that's the only mode it supports. Can change this post TP4
arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp:ro`, `/hostVar:/containerVar:rw`}, []string{os.Getenv("TEMP") + `:c:\containerTmp:rw`, os.Getenv("ProgramData") + `:c:\ContainerPD:rw`}) arr, tryit = setupPlatformVolume(
[]string{`/hostTmp:/containerTmp:ro`, `/hostVar:/containerVar:rw`},
[]string{os.Getenv("TEMP") + `:c:\containerTmp:rw`, os.Getenv("ProgramData") + `:c:\ContainerPD:rw`})
if _, hostConfig := mustParse(t, tryit); hostConfig.Binds == nil || compareRandomizedStrings(hostConfig.Binds[0], hostConfig.Binds[1], arr[0], arr[1]) != nil { if _, hostConfig := mustParse(t, tryit); hostConfig.Binds == nil || compareRandomizedStrings(hostConfig.Binds[0], hostConfig.Binds[1], arr[0], arr[1]) != nil {
t.Fatalf("Error parsing volume flags, `%s and %s` did not mount-bind correctly. Received %v", arr[0], arr[1], hostConfig.Binds) t.Fatalf("Error parsing volume flags, `%s and %s` did not mount-bind correctly. Received %v", arr[0], arr[1], hostConfig.Binds)
} }

View File

@ -17,7 +17,7 @@ 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.DockerCli) *cobra.Command { func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
opts := pruneOptions{filter: opts.NewFilterOpt()} opts := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -48,7 +48,7 @@ func NewPruneCommand(dockerCli *command.DockerCli) *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.DockerCli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { func runPrune(dockerCli command.Cli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) {
pruneFilters := command.PruneFilters(dockerCli, opts.filter.Value()) pruneFilters := command.PruneFilters(dockerCli, opts.filter.Value())
if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
@ -73,6 +73,6 @@ func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (spaceReclaimed u
// RunPrune calls the Container Prune API // RunPrune calls the Container Prune API
// This returns the amount of space reclaimed and a detailed output string // This returns the amount of space reclaimed and a detailed output string
func RunPrune(dockerCli *command.DockerCli, filter opts.FilterOpt) (uint64, string, error) { func RunPrune(dockerCli command.Cli, filter opts.FilterOpt) (uint64, string, error) {
return runPrune(dockerCli, pruneOptions{force: true, filter: filter}) return runPrune(dockerCli, pruneOptions{force: true, filter: filter})
} }

View File

@ -220,7 +220,7 @@ func runContainer(dockerCli *command.DockerCli, opts *runOptions, copts *contain
func attachContainer( func attachContainer(
ctx context.Context, ctx context.Context,
dockerCli *command.DockerCli, dockerCli command.Cli,
errCh *chan error, errCh *chan error,
config *container.Config, config *container.Config,
containerID string, containerID string,

View File

@ -8,7 +8,12 @@ import (
func TestCalculateBlockIO(t *testing.T) { func TestCalculateBlockIO(t *testing.T) {
blkio := types.BlkioStats{ blkio := types.BlkioStats{
IoServiceBytesRecursive: []types.BlkioStatEntry{{Major: 8, Minor: 0, Op: "read", Value: 1234}, {Major: 8, Minor: 1, Op: "read", Value: 4567}, {Major: 8, Minor: 0, Op: "write", Value: 123}, {Major: 8, Minor: 1, Op: "write", Value: 456}}, IoServiceBytesRecursive: []types.BlkioStatEntry{
{Major: 8, Minor: 0, Op: "read", Value: 1234},
{Major: 8, Minor: 1, Op: "read", Value: 4567},
{Major: 8, Minor: 0, Op: "write", Value: 123},
{Major: 8, Minor: 1, Op: "write", Value: 456},
},
} }
blkRead, blkWrite := calculateBlockIO(blkio) blkRead, blkWrite := calculateBlockIO(blkio)
if blkRead != 5801 { if blkRead != 5801 {

View File

@ -320,8 +320,36 @@ func TestContainerContextWriteJSON(t *testing.T) {
} }
expectedCreated := time.Unix(unix, 0).String() expectedCreated := time.Unix(unix, 0).String()
expectedJSONs := []map[string]interface{}{ expectedJSONs := []map[string]interface{}{
{"Command": "\"\"", "CreatedAt": expectedCreated, "ID": "containerID1", "Image": "ubuntu", "Labels": "", "LocalVolumes": "0", "Mounts": "", "Names": "foobar_baz", "Networks": "", "Ports": "", "RunningFor": "About a minute ago", "Size": "0B", "Status": ""}, {
{"Command": "\"\"", "CreatedAt": expectedCreated, "ID": "containerID2", "Image": "ubuntu", "Labels": "", "LocalVolumes": "0", "Mounts": "", "Names": "foobar_bar", "Networks": "", "Ports": "", "RunningFor": "About a minute ago", "Size": "0B", "Status": ""}, "Command": "\"\"",
"CreatedAt": expectedCreated,
"ID": "containerID1",
"Image": "ubuntu",
"Labels": "",
"LocalVolumes": "0",
"Mounts": "",
"Names": "foobar_baz",
"Networks": "",
"Ports": "",
"RunningFor": "About a minute ago",
"Size": "0B",
"Status": "",
},
{
"Command": "\"\"",
"CreatedAt": expectedCreated,
"ID": "containerID2",
"Image": "ubuntu",
"Labels": "",
"LocalVolumes": "0",
"Mounts": "",
"Names": "foobar_bar",
"Networks": "",
"Ports": "",
"RunningFor": "About a minute ago",
"Size": "0B",
"Status": "",
},
} }
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
err := ContainerWrite(Context{Format: "{{json .}}", Output: out}, containers) err := ContainerWrite(Context{Format: "{{json .}}", Output: out}, containers)

View File

@ -77,8 +77,8 @@ func TestHistoryContext_CreatedSince(t *testing.T) {
} }
func TestHistoryContext_CreatedBy(t *testing.T) { func TestHistoryContext_CreatedBy(t *testing.T) {
withTabs := `/bin/sh -c apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 && echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list && apt-get update && apt-get install --no-install-recommends --no-install-suggests -y ca-certificates nginx=${NGINX_VERSION} nginx-module-xslt nginx-module-geoip nginx-module-image-filter nginx-module-perl nginx-module-njs gettext-base && rm -rf /var/lib/apt/lists/*` withTabs := `/bin/sh -c apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 && echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list && apt-get update && apt-get install --no-install-recommends --no-install-suggests -y ca-certificates nginx=${NGINX_VERSION} nginx-module-xslt nginx-module-geoip nginx-module-image-filter nginx-module-perl nginx-module-njs gettext-base && rm -rf /var/lib/apt/lists/*` // nolint: lll
expected := `/bin/sh -c apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 && echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list && apt-get update && apt-get install --no-install-recommends --no-install-suggests -y ca-certificates nginx=${NGINX_VERSION} nginx-module-xslt nginx-module-geoip nginx-module-image-filter nginx-module-perl nginx-module-njs gettext-base && rm -rf /var/lib/apt/lists/*` expected := `/bin/sh -c apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 && echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list && apt-get update && apt-get install --no-install-recommends --no-install-suggests -y ca-certificates nginx=${NGINX_VERSION} nginx-module-xslt nginx-module-geoip nginx-module-image-filter nginx-module-perl nginx-module-njs gettext-base && rm -rf /var/lib/apt/lists/*` // nolint: lll
var ctx historyContext var ctx historyContext
cases := []historyCase{ cases := []historyCase{
@ -167,11 +167,19 @@ func TestHistoryContext_Table(t *testing.T) {
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
unixTime := time.Now().AddDate(0, 0, -1).Unix() unixTime := time.Now().AddDate(0, 0, -1).Unix()
histories := []image.HistoryResponseItem{ histories := []image.HistoryResponseItem{
{ID: "imageID1", Created: unixTime, CreatedBy: "/bin/bash ls && npm i && npm run test && karma -c karma.conf.js start && npm start && more commands here && the list goes on", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}}, {
ID: "imageID1",
Created: unixTime,
CreatedBy: "/bin/bash ls && npm i && npm run test && karma -c karma.conf.js start && npm start && more commands here && the list goes on",
Size: int64(182964289),
Comment: "Hi",
Tags: []string{"image:tag2"},
},
{ID: "imageID2", Created: unixTime, CreatedBy: "/bin/bash echo", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}}, {ID: "imageID2", Created: unixTime, CreatedBy: "/bin/bash echo", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}},
{ID: "imageID3", Created: unixTime, CreatedBy: "/bin/bash ls", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}}, {ID: "imageID3", Created: unixTime, CreatedBy: "/bin/bash ls", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}},
{ID: "imageID4", Created: unixTime, CreatedBy: "/bin/bash grep", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}}, {ID: "imageID4", Created: unixTime, CreatedBy: "/bin/bash grep", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}},
} }
// nolint: lll
expectedNoTrunc := `IMAGE CREATED CREATED BY SIZE COMMENT expectedNoTrunc := `IMAGE CREATED CREATED BY SIZE COMMENT
imageID1 24 hours ago /bin/bash ls && npm i && npm run test && karma -c karma.conf.js start && npm start && more commands here && the list goes on 183MB Hi imageID1 24 hours ago /bin/bash ls && npm i && npm run test && karma -c karma.conf.js start && npm start && more commands here && the list goes on 183MB Hi
imageID2 24 hours ago /bin/bash echo 183MB Hi imageID2 24 hours ago /bin/bash echo 183MB Hi

View File

@ -128,8 +128,23 @@ foobar_bar
for _, testcase := range cases { for _, testcase := range cases {
nodes := []swarm.Node{ nodes := []swarm.Node{
{ID: "nodeID1", Description: swarm.NodeDescription{Hostname: "foobar_baz"}, Status: swarm.NodeStatus{State: swarm.NodeState("foo")}, Spec: swarm.NodeSpec{Availability: swarm.NodeAvailability("drain")}, ManagerStatus: &swarm.ManagerStatus{Leader: true}}, {
{ID: "nodeID2", Description: swarm.NodeDescription{Hostname: "foobar_bar"}, Status: swarm.NodeStatus{State: swarm.NodeState("bar")}, Spec: swarm.NodeSpec{Availability: swarm.NodeAvailability("active")}, ManagerStatus: &swarm.ManagerStatus{Leader: false, Reachability: swarm.Reachability("Reachable")}}, ID: "nodeID1",
Description: swarm.NodeDescription{Hostname: "foobar_baz"},
Status: swarm.NodeStatus{State: swarm.NodeState("foo")},
Spec: swarm.NodeSpec{Availability: swarm.NodeAvailability("drain")},
ManagerStatus: &swarm.ManagerStatus{Leader: true},
},
{
ID: "nodeID2",
Description: swarm.NodeDescription{Hostname: "foobar_bar"},
Status: swarm.NodeStatus{State: swarm.NodeState("bar")},
Spec: swarm.NodeSpec{Availability: swarm.NodeAvailability("active")},
ManagerStatus: &swarm.ManagerStatus{
Leader: false,
Reachability: swarm.Reachability("Reachable"),
},
},
} }
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
testcase.context.Output = out testcase.context.Output = out

View File

@ -8,12 +8,13 @@ import (
) )
// NewImageCommand returns a cobra command for `image` subcommands // NewImageCommand returns a cobra command for `image` subcommands
// nolint: interfacer
func NewImageCommand(dockerCli *command.DockerCli) *cobra.Command { func NewImageCommand(dockerCli *command.DockerCli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "image", Use: "image",
Short: "Manage images", Short: "Manage images",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
} }
cmd.AddCommand( cmd.AddCommand(
NewBuildCommand(dockerCli), NewBuildCommand(dockerCli),

View File

@ -42,7 +42,7 @@ func trustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.Reposi
// PushTrustedReference pushes a canonical reference to the trust server. // PushTrustedReference pushes a canonical reference to the trust server.
// nolint: gocyclo // nolint: gocyclo
func PushTrustedReference(cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, in io.Reader) error { func PushTrustedReference(streams command.Streams, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, in io.Reader) error {
// If it is a trusted push we would like to find the target entry which match the // If it is a trusted push we would like to find the target entry which match the
// tag provided in the function and then do an AddTarget later. // tag provided in the function and then do an AddTarget later.
target := &client.Target{} target := &client.Target{}
@ -81,14 +81,14 @@ func PushTrustedReference(cli command.Cli, repoInfo *registry.RepositoryInfo, re
default: default:
// We want trust signatures to always take an explicit tag, // We want trust signatures to always take an explicit tag,
// otherwise it will act as an untrusted push. // otherwise it will act as an untrusted push.
if err := jsonmessage.DisplayJSONMessagesToStream(in, cli.Out(), nil); err != nil { if err := jsonmessage.DisplayJSONMessagesToStream(in, streams.Out(), nil); err != nil {
return err return err
} }
fmt.Fprintln(cli.Out(), "No tag specified, skipping trust metadata push") fmt.Fprintln(streams.Out(), "No tag specified, skipping trust metadata push")
return nil return nil
} }
if err := jsonmessage.DisplayJSONMessagesToStream(in, cli.Out(), handleTarget); err != nil { if err := jsonmessage.DisplayJSONMessagesToStream(in, streams.Out(), handleTarget); err != nil {
return err return err
} }
@ -97,15 +97,15 @@ func PushTrustedReference(cli command.Cli, repoInfo *registry.RepositoryInfo, re
} }
if target == nil { if target == nil {
fmt.Fprintln(cli.Out(), "No targets found, please provide a specific tag in order to sign it") fmt.Fprintln(streams.Out(), "No targets found, please provide a specific tag in order to sign it")
return nil return nil
} }
fmt.Fprintln(cli.Out(), "Signing and pushing trust metadata") fmt.Fprintln(streams.Out(), "Signing and pushing trust metadata")
repo, err := trust.GetNotaryRepository(cli, repoInfo, authConfig, "push", "pull") repo, err := trust.GetNotaryRepository(streams, repoInfo, authConfig, "push", "pull")
if err != nil { if err != nil {
fmt.Fprintf(cli.Out(), "Error establishing connection to notary repository: %s\n", err) fmt.Fprintf(streams.Out(), "Error establishing connection to notary repository: %s\n", err)
return err return err
} }
@ -132,7 +132,7 @@ func PushTrustedReference(cli command.Cli, repoInfo *registry.RepositoryInfo, re
if err := repo.Initialize([]string{rootKeyID}, data.CanonicalSnapshotRole); err != nil { if err := repo.Initialize([]string{rootKeyID}, data.CanonicalSnapshotRole); err != nil {
return trust.NotaryError(repoInfo.Name.Name(), err) return trust.NotaryError(repoInfo.Name.Name(), err)
} }
fmt.Fprintf(cli.Out(), "Finished initializing %q\n", repoInfo.Name.Name()) fmt.Fprintf(streams.Out(), "Finished initializing %q\n", repoInfo.Name.Name())
err = repo.AddTarget(target, data.CanonicalTargetsRole) err = repo.AddTarget(target, data.CanonicalTargetsRole)
case nil: case nil:
// already initialized and we have successfully downloaded the latest metadata // already initialized and we have successfully downloaded the latest metadata
@ -146,11 +146,11 @@ func PushTrustedReference(cli command.Cli, repoInfo *registry.RepositoryInfo, re
} }
if err != nil { if err != nil {
fmt.Fprintf(cli.Out(), "Failed to sign %q:%s - %s\n", repoInfo.Name.Name(), tag, err.Error()) fmt.Fprintf(streams.Out(), "Failed to sign %q:%s - %s\n", repoInfo.Name.Name(), tag, err.Error())
return trust.NotaryError(repoInfo.Name.Name(), err) return trust.NotaryError(repoInfo.Name.Name(), err)
} }
fmt.Fprintf(cli.Out(), "Successfully signed %q:%s\n", repoInfo.Name.Name(), tag) fmt.Fprintf(streams.Out(), "Successfully signed %q:%s\n", repoInfo.Name.Name(), tag)
return nil return nil
} }
@ -203,7 +203,7 @@ func addTargetToAllSignableRoles(repo *client.NotaryRepository, target *client.T
} }
// imagePushPrivileged push the image // imagePushPrivileged push the image
func imagePushPrivileged(ctx context.Context, cli command.Cli, authConfig types.AuthConfig, ref reference.Named, requestPrivilege types.RequestPrivilegeFunc) (io.ReadCloser, error) { func imagePushPrivileged(ctx context.Context, cli command.Cli, authConfig types.AuthConfig, ref reference.Reference, requestPrivilege types.RequestPrivilegeFunc) (io.ReadCloser, error) {
encodedAuth, err := command.EncodeAuthToBase64(authConfig) encodedAuth, err := command.EncodeAuthToBase64(authConfig)
if err != nil { if err != nil {
return nil, err return nil, err
@ -372,6 +372,7 @@ func convertTarget(t client.Target) (target, error) {
} }
// TagTrusted tags a trusted ref // TagTrusted tags a trusted ref
// nolint: interfacer
func TagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canonical, ref reference.NamedTagged) error { func TagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canonical, ref reference.NamedTagged) error {
// Use familiar references when interacting with client and output // Use familiar references when interacting with client and output
familiarRef := reference.FamiliarString(ref) familiarRef := reference.FamiliarString(ref)

View File

@ -8,12 +8,13 @@ import (
) )
// NewNetworkCommand returns a cobra command for `network` subcommands // NewNetworkCommand returns a cobra command for `network` subcommands
// nolint: interfacer
func NewNetworkCommand(dockerCli *command.DockerCli) *cobra.Command { func NewNetworkCommand(dockerCli *command.DockerCli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "network", Use: "network",
Short: "Manage networks", Short: "Manage networks",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
} }
cmd.AddCommand( cmd.AddCommand(
newConnectCommand(dockerCli), newConnectCommand(dockerCli),

View File

@ -17,7 +17,7 @@ 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.DockerCli) *cobra.Command { func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
opts := pruneOptions{filter: opts.NewFilterOpt()} opts := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -47,7 +47,7 @@ func NewPruneCommand(dockerCli *command.DockerCli) *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.DockerCli, opts pruneOptions) (output string, err error) { func runPrune(dockerCli command.Cli, opts pruneOptions) (output string, err error) {
pruneFilters := command.PruneFilters(dockerCli, opts.filter.Value()) pruneFilters := command.PruneFilters(dockerCli, opts.filter.Value())
if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
@ -71,7 +71,7 @@ func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (output string, e
// RunPrune calls the Network Prune API // RunPrune calls the Network Prune API
// This returns the amount of space reclaimed and a detailed output string // This returns the amount of space reclaimed and a detailed output string
func RunPrune(dockerCli *command.DockerCli, filter opts.FilterOpt) (uint64, string, error) { func RunPrune(dockerCli command.Cli, filter opts.FilterOpt) (uint64, string, error) {
output, err := runPrune(dockerCli, pruneOptions{force: true, filter: filter}) output, err := runPrune(dockerCli, pruneOptions{force: true, filter: filter})
return 0, output, err return 0, output, err
} }

View File

@ -12,12 +12,12 @@ import (
) )
// NewNodeCommand returns a cobra command for `node` subcommands // NewNodeCommand returns a cobra command for `node` subcommands
func NewNodeCommand(dockerCli *command.DockerCli) *cobra.Command { func NewNodeCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "node", Use: "node",
Short: "Manage Swarm nodes", Short: "Manage Swarm nodes",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
Tags: map[string]string{"version": "1.24"}, Tags: map[string]string{"version": "1.24"},
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -7,12 +7,13 @@ import (
) )
// NewPluginCommand returns a cobra command for `plugin` subcommands // NewPluginCommand returns a cobra command for `plugin` subcommands
// nolint: interfacer
func NewPluginCommand(dockerCli *command.DockerCli) *cobra.Command { func NewPluginCommand(dockerCli *command.DockerCli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "plugin", Use: "plugin",
Short: "Manage plugins", Short: "Manage plugins",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
Tags: map[string]string{"version": "1.25"}, Tags: map[string]string{"version": "1.25"},
} }

View File

@ -13,7 +13,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func newPushCommand(dockerCli *command.DockerCli) *cobra.Command { func newPushCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "push [OPTIONS] PLUGIN[:TAG]", Use: "push [OPTIONS] PLUGIN[:TAG]",
Short: "Push a plugin to a registry", Short: "Push a plugin to a registry",
@ -30,7 +30,7 @@ func newPushCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
func runPush(dockerCli *command.DockerCli, name string) error { func runPush(dockerCli command.Cli, name string) error {
named, err := reference.ParseNormalizedNamed(name) named, err := reference.ParseNormalizedNamed(name)
if err != nil { if err != nil {
return err return err

View File

@ -11,41 +11,41 @@ import (
) )
// NewContainerPruneCommand returns a cobra prune command for containers // NewContainerPruneCommand returns a cobra prune command for containers
func NewContainerPruneCommand(dockerCli *command.DockerCli) *cobra.Command { func NewContainerPruneCommand(dockerCli command.Cli) *cobra.Command {
return container.NewPruneCommand(dockerCli) return container.NewPruneCommand(dockerCli)
} }
// NewVolumePruneCommand returns a cobra prune command for volumes // NewVolumePruneCommand returns a cobra prune command for volumes
func NewVolumePruneCommand(dockerCli *command.DockerCli) *cobra.Command { func NewVolumePruneCommand(dockerCli command.Cli) *cobra.Command {
return volume.NewPruneCommand(dockerCli) return volume.NewPruneCommand(dockerCli)
} }
// NewImagePruneCommand returns a cobra prune command for images // NewImagePruneCommand returns a cobra prune command for images
func NewImagePruneCommand(dockerCli *command.DockerCli) *cobra.Command { func NewImagePruneCommand(dockerCli command.Cli) *cobra.Command {
return image.NewPruneCommand(dockerCli) return image.NewPruneCommand(dockerCli)
} }
// NewNetworkPruneCommand returns a cobra prune command for Networks // NewNetworkPruneCommand returns a cobra prune command for Networks
func NewNetworkPruneCommand(dockerCli *command.DockerCli) *cobra.Command { func NewNetworkPruneCommand(dockerCli command.Cli) *cobra.Command {
return network.NewPruneCommand(dockerCli) return network.NewPruneCommand(dockerCli)
} }
// RunContainerPrune executes a prune command for containers // RunContainerPrune executes a prune command for containers
func RunContainerPrune(dockerCli *command.DockerCli, filter opts.FilterOpt) (uint64, string, error) { func RunContainerPrune(dockerCli command.Cli, filter opts.FilterOpt) (uint64, string, error) {
return container.RunPrune(dockerCli, filter) return container.RunPrune(dockerCli, filter)
} }
// RunVolumePrune executes a prune command for volumes // RunVolumePrune executes a prune command for volumes
func RunVolumePrune(dockerCli *command.DockerCli, filter opts.FilterOpt) (uint64, string, error) { func RunVolumePrune(dockerCli command.Cli, filter opts.FilterOpt) (uint64, string, error) {
return volume.RunPrune(dockerCli, filter) return volume.RunPrune(dockerCli, filter)
} }
// RunImagePrune executes a prune command for images // RunImagePrune executes a prune command for images
func RunImagePrune(dockerCli *command.DockerCli, all bool, filter opts.FilterOpt) (uint64, string, error) { func RunImagePrune(dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error) {
return image.RunPrune(dockerCli, all, filter) return image.RunPrune(dockerCli, all, filter)
} }
// RunNetworkPrune executes a prune command for networks // RunNetworkPrune executes a prune command for networks
func RunNetworkPrune(dockerCli *command.DockerCli, filter opts.FilterOpt) (uint64, string, error) { func RunNetworkPrune(dockerCli command.Cli, filter opts.FilterOpt) (uint64, string, error) {
return network.RunPrune(dockerCli, filter) return network.RunPrune(dockerCli, filter)
} }

View File

@ -20,7 +20,7 @@ type loginOptions struct {
} }
// NewLoginCommand creates a new `docker login` command // NewLoginCommand creates a new `docker login` command
func NewLoginCommand(dockerCli *command.DockerCli) *cobra.Command { func NewLoginCommand(dockerCli command.Cli) *cobra.Command {
var opts loginOptions var opts loginOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -48,7 +48,7 @@ func NewLoginCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
func runLogin(dockerCli *command.DockerCli, opts loginOptions) error { func runLogin(dockerCli command.Cli, opts loginOptions) error {
ctx := context.Background() ctx := context.Background()
clnt := dockerCli.Client() clnt := dockerCli.Client()

View File

@ -12,7 +12,7 @@ import (
) )
// NewLogoutCommand creates a new `docker logout` command // NewLogoutCommand creates a new `docker logout` command
func NewLogoutCommand(dockerCli *command.DockerCli) *cobra.Command { func NewLogoutCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "logout [SERVER]", Use: "logout [SERVER]",
Short: "Log out from a Docker registry", Short: "Log out from a Docker registry",
@ -30,7 +30,7 @@ func NewLogoutCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
func runLogout(dockerCli *command.DockerCli, serverAddress string) error { func runLogout(dockerCli command.Cli, serverAddress string) error {
ctx := context.Background() ctx := context.Background()
var isDefaultRegistry bool var isDefaultRegistry bool

View File

@ -30,7 +30,7 @@ type searchOptions struct {
} }
// NewSearchCommand creates a new `docker search` command // NewSearchCommand creates a new `docker search` command
func NewSearchCommand(dockerCli *command.DockerCli) *cobra.Command { func NewSearchCommand(dockerCli command.Cli) *cobra.Command {
opts := searchOptions{filter: opts.NewFilterOpt()} opts := searchOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -58,7 +58,7 @@ func NewSearchCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
func runSearch(dockerCli *command.DockerCli, opts searchOptions) error { func runSearch(dockerCli command.Cli, opts searchOptions) error {
indexInfo, err := registry.ParseSearchIndexInfo(opts.term) indexInfo, err := registry.ParseSearchIndexInfo(opts.term)
if err != nil { if err != nil {
return err return err

View File

@ -8,12 +8,13 @@ import (
) )
// NewSecretCommand returns a cobra command for `secret` subcommands // NewSecretCommand returns a cobra command for `secret` subcommands
// nolint: interfacer
func NewSecretCommand(dockerCli *command.DockerCli) *cobra.Command { func NewSecretCommand(dockerCli *command.DockerCli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "secret", Use: "secret",
Short: "Manage Docker secrets", Short: "Manage Docker secrets",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
Tags: map[string]string{"version": "1.25"}, Tags: map[string]string{"version": "1.25"},
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -8,12 +8,13 @@ import (
) )
// NewServiceCommand returns a cobra command for `service` subcommands // NewServiceCommand returns a cobra command for `service` subcommands
// nolint: interfacer
func NewServiceCommand(dockerCli *command.DockerCli) *cobra.Command { func NewServiceCommand(dockerCli *command.DockerCli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "service", Use: "service",
Short: "Manage services", Short: "Manage services",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
Tags: map[string]string{"version": "1.24"}, Tags: map[string]string{"version": "1.24"},
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -593,7 +593,7 @@ func (opts *serviceOptions) ToStopGracePeriod(flags *pflag.FlagSet) *time.Durati
return nil return nil
} }
func (opts *serviceOptions) ToService(ctx context.Context, apiClient client.APIClient, flags *pflag.FlagSet) (swarm.ServiceSpec, error) { func (opts *serviceOptions) ToService(ctx context.Context, apiClient client.NetworkAPIClient, flags *pflag.FlagSet) (swarm.ServiceSpec, error) {
var service swarm.ServiceSpec var service swarm.ServiceSpec
envVariables, err := runconfigopts.ReadKVStrings(opts.envFile.GetAll(), opts.env.GetAll()) envVariables, err := runconfigopts.ReadKVStrings(opts.envFile.GetAll(), opts.env.GetAll())
@ -780,7 +780,8 @@ func addServiceFlags(flags *pflag.FlagSet, opts *serviceOptions, defaultFlagValu
flags.StringVar(&opts.update.order, flagUpdateOrder, "", flagDesc(flagUpdateOrder, `Update order ("start-first"|"stop-first")`)) flags.StringVar(&opts.update.order, flagUpdateOrder, "", flagDesc(flagUpdateOrder, `Update order ("start-first"|"stop-first")`))
flags.SetAnnotation(flagUpdateOrder, "version", []string{"1.29"}) flags.SetAnnotation(flagUpdateOrder, "version", []string{"1.29"})
flags.Uint64Var(&opts.rollback.parallelism, flagRollbackParallelism, defaultFlagValues.getUint64(flagRollbackParallelism), "Maximum number of tasks rolled back simultaneously (0 to roll back all at once)") flags.Uint64Var(&opts.rollback.parallelism, flagRollbackParallelism, defaultFlagValues.getUint64(flagRollbackParallelism),
"Maximum number of tasks rolled back simultaneously (0 to roll back all at once)")
flags.SetAnnotation(flagRollbackParallelism, "version", []string{"1.28"}) flags.SetAnnotation(flagRollbackParallelism, "version", []string{"1.28"})
flags.DurationVar(&opts.rollback.delay, flagRollbackDelay, 0, flagDesc(flagRollbackDelay, "Delay between task rollbacks (ns|us|ms|s|m|h)")) flags.DurationVar(&opts.rollback.delay, flagRollbackDelay, 0, flagDesc(flagRollbackDelay, "Delay between task rollbacks (ns|us|ms|s|m|h)"))
flags.SetAnnotation(flagRollbackDelay, "version", []string{"1.28"}) flags.SetAnnotation(flagRollbackDelay, "version", []string{"1.28"})

View File

@ -27,7 +27,7 @@ type psOptions struct {
filter opts.FilterOpt filter opts.FilterOpt
} }
func newPsCommand(dockerCli *command.DockerCli) *cobra.Command { func newPsCommand(dockerCli command.Cli) *cobra.Command {
opts := psOptions{filter: opts.NewFilterOpt()} opts := psOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -49,7 +49,7 @@ func newPsCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
func runPS(dockerCli *command.DockerCli, opts psOptions) error { func runPS(dockerCli command.Cli, opts psOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
ctx := context.Background() ctx := context.Background()

View File

@ -15,7 +15,7 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
) )
func resolveServiceImageDigest(dockerCli *command.DockerCli, service *swarm.ServiceSpec) error { func resolveServiceImageDigest(dockerCli command.Cli, service *swarm.ServiceSpec) error {
if !command.IsTrusted() { if !command.IsTrusted() {
// Digests are resolved by the daemon when not using content // Digests are resolved by the daemon when not using content
// trust. // trust.
@ -51,7 +51,7 @@ func resolveServiceImageDigest(dockerCli *command.DockerCli, service *swarm.Serv
return nil return nil
} }
func trustedResolveDigest(ctx context.Context, cli *command.DockerCli, ref reference.NamedTagged) (reference.Canonical, error) { func trustedResolveDigest(ctx context.Context, cli command.Cli, ref reference.NamedTagged) (reference.Canonical, error) {
repoInfo, err := registry.ParseRepositoryInfo(ref) repoInfo, err := registry.ParseRepositoryInfo(ref)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -213,7 +213,7 @@ func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *service
} }
// nolint: gocyclo // nolint: gocyclo
func updateService(ctx context.Context, apiClient client.APIClient, flags *pflag.FlagSet, spec *swarm.ServiceSpec) error { func updateService(ctx context.Context, apiClient client.NetworkAPIClient, flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
updateString := func(flag string, field *string) { updateString := func(flag string, field *string) {
if flags.Changed(flag) { if flags.Changed(flag) {
*field, _ = flags.GetString(flag) *field, _ = flags.GetString(flag)

View File

@ -7,12 +7,13 @@ import (
) )
// NewStackCommand returns a cobra command for `stack` subcommands // NewStackCommand returns a cobra command for `stack` subcommands
// nolint: interfacer
func NewStackCommand(dockerCli *command.DockerCli) *cobra.Command { func NewStackCommand(dockerCli *command.DockerCli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "stack", Use: "stack",
Short: "Manage Docker stacks", Short: "Manage Docker stacks",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
Tags: map[string]string{"version": "1.25"}, Tags: map[string]string{"version": "1.25"},
} }
cmd.AddCommand( cmd.AddCommand(
@ -26,7 +27,7 @@ func NewStackCommand(dockerCli *command.DockerCli) *cobra.Command {
} }
// NewTopLevelDeployCommand returns a command for `docker deploy` // NewTopLevelDeployCommand returns a command for `docker deploy`
func NewTopLevelDeployCommand(dockerCli *command.DockerCli) *cobra.Command { func NewTopLevelDeployCommand(dockerCli command.Cli) *cobra.Command {
cmd := newDeployCommand(dockerCli) cmd := newDeployCommand(dockerCli)
// Remove the aliases at the top level // Remove the aliases at the top level
cmd.Aliases = []string{} cmd.Aliases = []string{}

View File

@ -24,7 +24,7 @@ type deployOptions struct {
prune bool prune bool
} }
func newDeployCommand(dockerCli *command.DockerCli) *cobra.Command { func newDeployCommand(dockerCli command.Cli) *cobra.Command {
var opts deployOptions var opts deployOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -47,7 +47,7 @@ func newDeployCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
func runDeploy(dockerCli *command.DockerCli, opts deployOptions) error { func runDeploy(dockerCli command.Cli, opts deployOptions) error {
ctx := context.Background() ctx := context.Background()
switch { switch {
@ -66,7 +66,7 @@ func runDeploy(dockerCli *command.DockerCli, opts deployOptions) error {
// a swarm manager. This is necessary because we must create networks before we // a swarm manager. This is necessary because we must create networks before we
// create services, but the API call for creating a network does not return a // create services, but the API call for creating a network does not return a
// proper status code when it can't create a network in the "global" scope. // proper status code when it can't create a network in the "global" scope.
func checkDaemonIsSwarmManager(ctx context.Context, dockerCli *command.DockerCli) error { func checkDaemonIsSwarmManager(ctx context.Context, dockerCli command.Cli) error {
info, err := dockerCli.Client().Info(ctx) info, err := dockerCli.Client().Info(ctx)
if err != nil { if err != nil {
return err return err

View File

@ -9,7 +9,7 @@ import (
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
) )
func deployBundle(ctx context.Context, dockerCli *command.DockerCli, opts deployOptions) error { func deployBundle(ctx context.Context, dockerCli command.Cli, opts deployOptions) error {
bundle, err := loadBundlefile(dockerCli.Err(), opts.namespace, opts.bundlefile) bundle, err := loadBundlefile(dockerCli.Err(), opts.namespace, opts.bundlefile)
if err != nil { if err != nil {
return err return err

View File

@ -20,7 +20,7 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
) )
func deployCompose(ctx context.Context, dockerCli *command.DockerCli, opts deployOptions) error { func deployCompose(ctx context.Context, dockerCli command.Cli, opts deployOptions) error {
configDetails, err := getConfigDetails(opts.composefile) configDetails, err := getConfigDetails(opts.composefile)
if err != nil { if err != nil {
return err return err
@ -161,7 +161,7 @@ func getConfigFile(filename string) (*composetypes.ConfigFile, error) {
func validateExternalNetworks( func validateExternalNetworks(
ctx context.Context, ctx context.Context,
dockerCli *command.DockerCli, dockerCli command.Cli,
externalNetworks []string) error { externalNetworks []string) error {
client := dockerCli.Client() client := dockerCli.Client()
@ -183,7 +183,7 @@ func validateExternalNetworks(
func createSecrets( func createSecrets(
ctx context.Context, ctx context.Context,
dockerCli *command.DockerCli, dockerCli command.Cli,
namespace convert.Namespace, namespace convert.Namespace,
secrets []swarm.SecretSpec, secrets []swarm.SecretSpec,
) error { ) error {
@ -210,7 +210,7 @@ func createSecrets(
func createNetworks( func createNetworks(
ctx context.Context, ctx context.Context,
dockerCli *command.DockerCli, dockerCli command.Cli,
namespace convert.Namespace, namespace convert.Namespace,
networks map[string]types.NetworkCreate, networks map[string]types.NetworkCreate,
) error { ) error {
@ -247,7 +247,7 @@ func createNetworks(
func deployServices( func deployServices(
ctx context.Context, ctx context.Context,
dockerCli *command.DockerCli, dockerCli command.Cli,
services map[string]swarm.ServiceSpec, services map[string]swarm.ServiceSpec,
namespace convert.Namespace, namespace convert.Namespace,
sendAuth bool, sendAuth bool,

View File

@ -24,7 +24,7 @@ type psOptions struct {
format string format string
} }
func newPsCommand(dockerCli *command.DockerCli) *cobra.Command { func newPsCommand(dockerCli command.Cli) *cobra.Command {
opts := psOptions{filter: opts.NewFilterOpt()} opts := psOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -46,7 +46,7 @@ func newPsCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
func runPS(dockerCli *command.DockerCli, opts psOptions) error { func runPS(dockerCli command.Cli, opts psOptions) error {
namespace := opts.namespace namespace := opts.namespace
client := dockerCli.Client() client := dockerCli.Client()
ctx := context.Background() ctx := context.Background()

View File

@ -8,12 +8,13 @@ import (
) )
// NewSwarmCommand returns a cobra command for `swarm` subcommands // NewSwarmCommand returns a cobra command for `swarm` subcommands
func NewSwarmCommand(dockerCli *command.DockerCli) *cobra.Command { // nolint: interfacer
func NewSwarmCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "swarm", Use: "swarm",
Short: "Manage Swarm", Short: "Manage Swarm",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
Tags: map[string]string{"version": "1.24"}, Tags: map[string]string{"version": "1.24"},
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -80,7 +80,10 @@ func runUnlockKey(dockerCli command.Cli, opts unlockKeyOptions) error {
func printUnlockCommand(ctx context.Context, dockerCli command.Cli, unlockKey string) { func printUnlockCommand(ctx context.Context, dockerCli command.Cli, unlockKey string) {
if len(unlockKey) > 0 { if len(unlockKey) > 0 {
fmt.Fprintf(dockerCli.Out(), "To unlock a swarm manager after it restarts, run the `docker swarm unlock`\ncommand and provide the following key:\n\n %s\n\nPlease remember to store this key in a password manager, since without it you\nwill not be able to restart the manager.\n", unlockKey) fmt.Fprintf(dockerCli.Out(), "To unlock a swarm manager after it restarts, "+
"run the `docker swarm unlock`\ncommand and provide the following key:\n\n %s\n\n"+
"Please remember to store this key in a password manager, since without it you\n"+
"will not be able to restart the manager.\n", unlockKey)
} }
return return
} }

View File

@ -1,19 +1,19 @@
package system package system
import ( import (
"github.com/spf13/cobra"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/spf13/cobra"
) )
// NewSystemCommand returns a cobra command for `system` subcommands // NewSystemCommand returns a cobra command for `system` subcommands
// nolint: interfacer
func NewSystemCommand(dockerCli *command.DockerCli) *cobra.Command { func NewSystemCommand(dockerCli *command.DockerCli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "system", Use: "system",
Short: "Manage Docker", Short: "Manage Docker",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
} }
cmd.AddCommand( cmd.AddCommand(
NewEventsCommand(dockerCli), NewEventsCommand(dockerCli),

View File

@ -330,7 +330,9 @@ func printStorageDriverWarnings(dockerCli *command.DockerCli, info types.Info) {
for _, pair := range info.DriverStatus { for _, pair := range info.DriverStatus {
if pair[0] == "Data loop file" { if pair[0] == "Data loop file" {
fmt.Fprintf(dockerCli.Err(), "WARNING: %s: usage of loopback devices is strongly discouraged for production use.\n Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.\n", info.Driver) fmt.Fprintf(dockerCli.Err(), "WARNING: %s: usage of loopback devices is "+
"strongly discouraged for production use.\n "+
"Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.\n", info.Driver)
} }
if pair[0] == "Supports d_type" && pair[1] == "false" { if pair[0] == "Supports d_type" && pair[1] == "false" {
backingFs := getBackingFs(info) backingFs := getBackingFs(info)

View File

@ -18,7 +18,7 @@ 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.DockerCli) *cobra.Command { func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
opts := pruneOptions{filter: opts.NewFilterOpt()} opts := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -51,7 +51,7 @@ Are you sure you want to continue?`
allImageDesc = `- all images without at least one container associated to them` allImageDesc = `- all images without at least one container associated to them`
) )
func runPrune(dockerCli *command.DockerCli, options pruneOptions) error { func runPrune(dockerCli command.Cli, options pruneOptions) error {
var message string var message string
if options.all { if options.all {
@ -66,7 +66,7 @@ func runPrune(dockerCli *command.DockerCli, options pruneOptions) error {
var spaceReclaimed uint64 var spaceReclaimed uint64
for _, pruneFn := range []func(dockerCli *command.DockerCli, filter opts.FilterOpt) (uint64, string, error){ for _, pruneFn := range []func(dockerCli command.Cli, filter opts.FilterOpt) (uint64, string, error){
prune.RunContainerPrune, prune.RunContainerPrune,
prune.RunVolumePrune, prune.RunVolumePrune,
prune.RunNetworkPrune, prune.RunNetworkPrune,

View File

@ -69,7 +69,7 @@ func PrettyPrint(i interface{}) string {
// the user input 'y' or 'Y' it returns true other false. If no // the user input 'y' or 'Y' it returns true other false. If no
// message is provided "Are you sure you want to proceed? [y/N] " // message is provided "Are you sure you want to proceed? [y/N] "
// will be used instead. // will be used instead.
func PromptForConfirmation(ins *InStream, outs *OutStream, message string) bool { func PromptForConfirmation(ins io.Reader, outs io.Writer, message string) bool {
if message == "" { if message == "" {
message = "Are you sure you want to proceed?" message = "Are you sure you want to proceed?"
} }

View File

@ -7,12 +7,12 @@ import (
) )
// NewVolumeCommand returns a cobra command for `volume` subcommands // NewVolumeCommand returns a cobra command for `volume` subcommands
func NewVolumeCommand(dockerCli *command.DockerCli) *cobra.Command { func NewVolumeCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "volume COMMAND", Use: "volume COMMAND",
Short: "Manage volumes", Short: "Manage volumes",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: dockerCli.ShowHelp, RunE: command.ShowHelp(dockerCli.Err()),
Tags: map[string]string{"version": "1.21"}, Tags: map[string]string{"version": "1.21"},
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -73,6 +73,6 @@ func runPrune(dockerCli command.Cli, opts pruneOptions) (spaceReclaimed uint64,
// RunPrune calls the Volume Prune API // RunPrune calls the Volume Prune API
// This returns the amount of space reclaimed and a detailed output string // This returns the amount of space reclaimed and a detailed output string
func RunPrune(dockerCli *command.DockerCli, filter opts.FilterOpt) (uint64, string, error) { func RunPrune(dockerCli command.Cli, filter opts.FilterOpt) (uint64, string, error) {
return runPrune(dockerCli, pruneOptions{force: true, filter: filter}) return runPrune(dockerCli, pruneOptions{force: true, filter: filter})
} }

View File

@ -37,7 +37,7 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
showVersion() showVersion()
return nil return nil
} }
return dockerCli.ShowHelp(cmd, args) return command.ShowHelp(dockerCli.Err())(cmd, args)
}, },
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// daemon command is special, we redirect directly to another binary // daemon command is special, we redirect directly to another binary

View File

@ -23,5 +23,3 @@ COPY . /go/src/github.com/docker/cli
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0
WORKDIR /go/src/github.com/docker/cli WORKDIR /go/src/github.com/docker/cli
CMD ["make", "ci"]

View File

@ -1,5 +1,6 @@
{ {
"Vendor": true, "Vendor": true,
"Deadline": "2m",
"Sort": ["linter", "severity", "path"], "Sort": ["linter", "severity", "path"],
"Exclude": ["cli/compose/schema/bindata.go"], "Exclude": ["cli/compose/schema/bindata.go"],
@ -11,8 +12,11 @@
"goimports", "goimports",
"golint", "golint",
"ineffassign", "ineffassign",
"interfacer",
"lll",
"vet" "vet"
], ],
"Cyclo": 19 "Cyclo": 19,
"LineLength": 200
} }