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

Commit ba746d2

Browse files
Merge component 'cli' from git@github.com:docker/cli 19.03
2 parents 56856a4 + 962e636 commit ba746d2

4 files changed

Lines changed: 24 additions & 14 deletions

File tree

components/cli/cli/command/cli.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ func (cli *DockerCli) ServerInfo() ServerInfo {
148148
// ClientInfo returns the client details for the cli
149149
func (cli *DockerCli) ClientInfo() ClientInfo {
150150
if cli.clientInfo == nil {
151-
_ = cli.loadClientInfo()
151+
if err := cli.loadClientInfo(); err != nil {
152+
panic(err)
153+
}
152154
}
153155
return *cli.clientInfo
154156
}
@@ -277,6 +279,11 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
277279
}
278280
}
279281
cli.initializeFromClient()
282+
283+
if err := cli.loadClientInfo(); err != nil {
284+
return err
285+
}
286+
280287
return nil
281288
}
282289

components/cli/cli/connhelper/connhelper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func GetConnectionHelper(daemonURL string) (*ConnectionHelper, error) {
3434
}
3535
return &ConnectionHelper{
3636
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
37-
return commandconn.New(ctx, "ssh", append(sp.Args(), []string{"--", "docker", "system", "dial-stdio"}...)...)
37+
return commandconn.New(ctx, "ssh", sp.Args("docker", "system", "dial-stdio")...)
3838
},
3939
Host: "http://docker",
4040
}, nil

components/cli/cli/connhelper/ssh/ssh.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ type Spec struct {
4949
Port string
5050
}
5151

52-
// Args returns args except "ssh" itself and "-- ..."
53-
func (sp *Spec) Args() []string {
52+
// Args returns args except "ssh" itself combined with optional additional command args
53+
func (sp *Spec) Args(add ...string) []string {
5454
var args []string
5555
if sp.User != "" {
5656
args = append(args, "-l", sp.User)
5757
}
5858
if sp.Port != "" {
5959
args = append(args, "-p", sp.Port)
6060
}
61-
args = append(args, sp.Host)
61+
args = append(args, "--", sp.Host)
62+
args = append(args, add...)
6263
return args
6364
}

components/cli/cli/connhelper/ssh/ssh_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ func TestParseURL(t *testing.T) {
1616
{
1717
url: "ssh://foo",
1818
expectedArgs: []string{
19-
"foo",
19+
"--", "foo",
2020
},
2121
},
2222
{
2323
url: "ssh://me@foo:10022",
2424
expectedArgs: []string{
2525
"-l", "me",
2626
"-p", "10022",
27-
"foo",
27+
"--", "foo",
2828
},
2929
},
3030
{
@@ -53,12 +53,14 @@ func TestParseURL(t *testing.T) {
5353
},
5454
}
5555
for _, tc := range testCases {
56-
sp, err := ParseURL(tc.url)
57-
if tc.expectedError == "" {
58-
assert.NilError(t, err)
59-
assert.Check(t, is.DeepEqual(tc.expectedArgs, sp.Args()))
60-
} else {
61-
assert.ErrorContains(t, err, tc.expectedError)
62-
}
56+
t.Run(tc.url, func(t *testing.T) {
57+
sp, err := ParseURL(tc.url)
58+
if tc.expectedError == "" {
59+
assert.NilError(t, err)
60+
assert.Check(t, is.DeepEqual(tc.expectedArgs, sp.Args()))
61+
} else {
62+
assert.ErrorContains(t, err, tc.expectedError)
63+
}
64+
})
6365
}
6466
}

0 commit comments

Comments
 (0)