Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 84bf606

Browse files
Merge component 'cli' from git@github.com:docker/cli 19.03
2 parents aa6bfe7 + 3a9fa3f commit 84bf606

87 files changed

Lines changed: 297 additions & 295 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/cli/.golangci.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
linters:
2+
enable:
3+
- bodyclose
4+
- deadcode
5+
- dogsled
6+
- gocyclo
7+
- goimports
8+
- golint
9+
- gosec
10+
- gosimple
11+
- govet
12+
- ineffassign
13+
- interfacer
14+
- lll
15+
- megacheck
16+
- misspell
17+
- nakedret
18+
- staticcheck
19+
- structcheck
20+
- typecheck
21+
- unconvert
22+
- unparam
23+
- unused
24+
- varcheck
25+
26+
disable:
27+
- errcheck
28+
29+
run:
30+
timeout: 5m
31+
skip-dirs:
32+
- cli/command/stack/kubernetes/api/openapi
33+
- cli/command/stack/kubernetes/api/client
34+
skip-files:
35+
- cli/compose/schema/bindata.go
36+
- .*generated.*
37+
38+
linters-settings:
39+
gocyclo:
40+
min-complexity: 16
41+
govet:
42+
check-shadowing: false
43+
lll:
44+
line-length: 200
45+
nakedret:
46+
command: nakedret
47+
pattern: ^(?P<path>.*?\\.go):(?P<line>\\d+)\\s*(?P<message>.*)$
48+
49+
issues:
50+
# The default exclusion rules are a bit too permissive, so copying the relevant ones below
51+
exclude-use-default: false
52+
53+
exclude:
54+
- parameter .* always receives
55+
56+
exclude-rules:
57+
# These are copied from the default exclude rules, except for "ineffective break statement"
58+
# and GoDoc checks.
59+
# https://github.com/golangci/golangci-lint/blob/0cc87df732aaf1d5ad9ce9ca538d38d916918b36/pkg/config/config.go#L36
60+
- text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked"
61+
linters:
62+
- errcheck
63+
- text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
64+
linters:
65+
- golint
66+
- text: "G103: Use of unsafe calls should be audited"
67+
linters:
68+
- gosec
69+
- text: "G104: Errors unhandled"
70+
linters:
71+
- gosec
72+
- text: "G204: Subprocess launch(ed with (variable|function call)|ing should be audited)"
73+
linters:
74+
- gosec
75+
- text: "(G301|G302): (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)"
76+
linters:
77+
- gosec
78+
- text: "G304: Potential file inclusion via variable"
79+
linters:
80+
- gosec
81+
- text: "(G201|G202): SQL string (formatting|concatenation)"
82+
linters:
83+
- gosec

components/cli/cli/command/cli_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func TestInitializeFromClient(t *testing.T) {
152152
}
153153

154154
for _, testcase := range testcases {
155+
testcase := testcase
155156
t.Run(testcase.doc, func(t *testing.T) {
156157
apiclient := &fakeClient{
157158
pingFunc: testcase.pingFunc,
@@ -189,6 +190,7 @@ func TestExperimentalCLI(t *testing.T) {
189190
}
190191

191192
for _, testcase := range testcases {
193+
testcase := testcase
192194
t.Run(testcase.doc, func(t *testing.T) {
193195
dir := fs.NewDir(t, testcase.doc, fs.WithFile("config.json", testcase.configfile))
194196
defer dir.Remove()
@@ -242,6 +244,7 @@ func TestGetClientWithPassword(t *testing.T) {
242244
}
243245

244246
for _, testcase := range testcases {
247+
testcase := testcase
245248
t.Run(testcase.doc, func(t *testing.T) {
246249
passRetriever := func(_, _ string, _ bool, attempts int) (passphrase string, giveup bool, err error) {
247250
// Always return an invalid pass first to test iteration
@@ -294,11 +297,12 @@ func TestNewDockerCliAndOperators(t *testing.T) {
294297
inbuf := bytes.NewBuffer([]byte("input"))
295298
outbuf := bytes.NewBuffer(nil)
296299
errbuf := bytes.NewBuffer(nil)
297-
cli.Apply(
300+
err = cli.Apply(
298301
WithInputStream(ioutil.NopCloser(inbuf)),
299302
WithOutputStream(outbuf),
300303
WithErrorStream(errbuf),
301304
)
305+
assert.NilError(t, err)
302306
// Check input stream
303307
inputStream, err := ioutil.ReadAll(cli.In())
304308
assert.NilError(t, err)

components/cli/cli/command/config/inspect_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import (
77
"time"
88

99
"github.com/docker/cli/internal/test"
10+
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
1011
"github.com/docker/docker/api/types/swarm"
1112
"github.com/pkg/errors"
12-
// Import builders to get the builder function as package function
13-
. "github.com/docker/cli/internal/test/builders"
1413
"gotest.tools/assert"
1514
"gotest.tools/golden"
1615
)

components/cli/cli/command/config/ls_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import (
77

88
"github.com/docker/cli/cli/config/configfile"
99
"github.com/docker/cli/internal/test"
10+
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
1011
"github.com/docker/docker/api/types"
1112
"github.com/docker/docker/api/types/swarm"
1213
"github.com/pkg/errors"
13-
// Import builders to get the builder function as package function
14-
. "github.com/docker/cli/internal/test/builders"
1514
"gotest.tools/assert"
1615
is "gotest.tools/assert/cmp"
1716
"gotest.tools/golden"

components/cli/cli/command/container/attach.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"io"
7-
"net/http/httputil"
87

98
"github.com/docker/cli/cli"
109
"github.com/docker/cli/cli/command"
@@ -103,10 +102,7 @@ func runAttach(dockerCli command.Cli, opts *attachOptions) error {
103102
}
104103

105104
resp, errAttach := client.ContainerAttach(ctx, opts.container, options)
106-
if errAttach != nil && errAttach != httputil.ErrPersistEOF {
107-
// ContainerAttach returns an ErrPersistEOF (connection closed)
108-
// means server met an error and put it in Hijacked connection
109-
// keep the error and read detailed error message from hijacked connection later
105+
if errAttach != nil {
110106
return errAttach
111107
}
112108
defer resp.Close()
@@ -142,10 +138,6 @@ func runAttach(dockerCli command.Cli, opts *attachOptions) error {
142138
return err
143139
}
144140

145-
if errAttach != nil {
146-
return errAttach
147-
}
148-
149141
return getExitStatus(errC, resultC)
150142
}
151143

components/cli/cli/command/container/create_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
151151
},
152152
}
153153
for _, tc := range testCases {
154+
tc := tc
154155
cli := test.NewFakeCli(&fakeClient{
155156
createContainerFunc: func(config *container.Config,
156157
hostConfig *container.HostConfig,
@@ -209,6 +210,7 @@ func TestNewCreateCommandWithWarnings(t *testing.T) {
209210
},
210211
}
211212
for _, tc := range testCases {
213+
tc := tc
212214
t.Run(tc.name, func(t *testing.T) {
213215
cli := test.NewFakeCli(&fakeClient{
214216
createContainerFunc: func(config *container.Config,

components/cli/cli/command/container/list_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import (
77

88
"github.com/docker/cli/cli/config/configfile"
99
"github.com/docker/cli/internal/test"
10+
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
1011
"github.com/docker/docker/api/types"
11-
// Import builders to get the builder function as package function
12-
. "github.com/docker/cli/internal/test/builders"
1312
"gotest.tools/assert"
1413
"gotest.tools/golden"
1514
)

components/cli/cli/command/container/opts_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func setupRunFlags() (*pflag.FlagSet, *containerOptions) {
6565
}
6666

6767
func parseMustError(t *testing.T, args string) {
68-
_, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " "))
68+
_, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) //nolint:dogsled
6969
assert.ErrorContains(t, err, "", args)
7070
}
7171

@@ -539,7 +539,7 @@ func TestParseModes(t *testing.T) {
539539
}
540540

541541
// uts ko
542-
_, _, _, err = parseRun([]string{"--uts=container:", "img", "cmd"})
542+
_, _, _, err = parseRun([]string{"--uts=container:", "img", "cmd"}) //nolint:dogsled
543543
assert.ErrorContains(t, err, "--uts: invalid UTS mode")
544544

545545
// uts ok
@@ -600,7 +600,7 @@ func TestParseRestartPolicy(t *testing.T) {
600600

601601
func TestParseRestartPolicyAutoRemove(t *testing.T) {
602602
expected := "Conflicting options: --restart and --rm"
603-
_, _, _, err := parseRun([]string{"--rm", "--restart=always", "img", "cmd"})
603+
_, _, _, err := parseRun([]string{"--rm", "--restart=always", "img", "cmd"}) //nolint:dogsled
604604
if err == nil || err.Error() != expected {
605605
t.Fatalf("Expected error %v, but got none", expected)
606606
}

components/cli/cli/command/container/run.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"io"
7-
"net/http/httputil"
87
"os"
98
"runtime"
109
"strings"
@@ -248,10 +247,7 @@ func attachContainer(
248247
}
249248

250249
resp, errAttach := dockerCli.Client().ContainerAttach(ctx, containerID, options)
251-
if errAttach != nil && errAttach != httputil.ErrPersistEOF {
252-
// ContainerAttach returns an ErrPersistEOF (connection closed)
253-
// means server met an error and put it in Hijacked connection
254-
// keep the error and read detailed error message from hijacked connection later
250+
if errAttach != nil {
255251
return nil, errAttach
256252
}
257253

components/cli/cli/command/container/start.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"io"
7-
"net/http/httputil"
87
"strings"
98

109
"github.com/docker/cli/cli"
@@ -98,10 +97,7 @@ func runStart(dockerCli command.Cli, opts *startOptions) error {
9897
}
9998

10099
resp, errAttach := dockerCli.Client().ContainerAttach(ctx, c.ID, options)
101-
if errAttach != nil && errAttach != httputil.ErrPersistEOF {
102-
// ContainerAttach return an ErrPersistEOF (connection closed)
103-
// means server met an error and already put it in Hijacked connection,
104-
// we would keep the error and read the detailed error message from hijacked connection
100+
if errAttach != nil {
105101
return errAttach
106102
}
107103
defer resp.Close()
@@ -154,7 +150,7 @@ func runStart(dockerCli command.Cli, opts *startOptions) error {
154150
}
155151
}
156152
if attachErr := <-cErr; attachErr != nil {
157-
if _, ok := err.(term.EscapeError); ok {
153+
if _, ok := attachErr.(term.EscapeError); ok {
158154
// The user entered the detach escape sequence.
159155
return nil
160156
}

0 commit comments

Comments
 (0)