Skip to content

Commit 35bf3cd

Browse files
authored
Merge pull request #23 from mask-pp/fix_some_carps
fix some carps
2 parents ff989ec + 14125d5 commit 35bf3cd

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed
File renamed without changes.

internal/command/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ type DebugCli struct {
6363
}
6464

6565
// NewDebugCli new DebugCli
66-
func NewDebugCli(ops ...DebugCliOption) (*DebugCli, error) {
67-
cli := &DebugCli{}
66+
func NewDebugCli(ctx context.Context, ops ...DebugCliOption) (*DebugCli, error) {
67+
cli := &DebugCli{ctx: ctx}
6868
if err := cli.Apply(ops...); err != nil {
6969
return nil, err
7070
}

internal/command/root.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ func newExecCommand() *cobra.Command {
4848
RunE: func(cmd *cobra.Command, args []string) error {
4949
options.container = args[0]
5050
options.command = args[1:]
51-
_ = runExec(options)
52-
return nil
51+
return runExec(options)
5352
},
5453
}
5554

@@ -98,23 +97,17 @@ func buildCli(ctx context.Context, options execOptions) (*DebugCli, error) {
9897
opts = append(opts, WithClientConfig(dockerConfig))
9998
} else {
10099
name := conf.DockerConfigDefault
101-
opt, ok := conf.DockerConfig[conf.DockerConfigDefault]
102100
if options.name != "" {
103101
name = options.name
104-
opt, ok = conf.DockerConfig[options.name]
105102
}
103+
opt, ok := conf.DockerConfig[name]
106104
if !ok {
107105
return nil, errors.Errorf("not find %s docker config", name)
108106
}
109107
opts = append(opts, WithClientConfig(opt))
110108
}
111109

112-
cli, err := NewDebugCli(opts...)
113-
if err != nil {
114-
return nil, err
115-
}
116-
cli.ctx = ctx
117-
return cli, err
110+
return NewDebugCli(ctx, opts...)
118111
}
119112

120113
func runExec(options execOptions) error {
@@ -184,9 +177,9 @@ func runExec(options execOptions) error {
184177
}
185178

186179
errCh := make(chan error, 1)
180+
defer close(errCh)
187181

188182
go func() {
189-
defer close(errCh)
190183
errCh <- func() error {
191184
return cli.ExecStart(options, resp.ID)
192185
}()
@@ -197,8 +190,7 @@ func runExec(options execOptions) error {
197190
}
198191
}
199192

200-
err = <-errCh
201-
if err != nil {
193+
if err = <-errCh; err != nil {
202194
logrus.Debugf("Error hijack: %s", err)
203195
return err
204196
}

0 commit comments

Comments
 (0)