avoid use of channels in API for gRPC compatibility

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-02-10 14:20:32 +01:00
parent 752edcce65
commit d9fe745cc0
No known key found for this signature in database
GPG key ID: 9858809D6F8F6E7E
11 changed files with 80 additions and 21 deletions

View file

@ -70,7 +70,9 @@ func runStart(ctx context.Context, opts startOptions, services []string) error {
queue: queue,
}
err = c.ComposeService().Start(ctx, project, compose.StartOptions{
Attach: queue,
Attach: func(event compose.ContainerEvent) {
queue <- event
},
})
if err != nil {
return err

View file

@ -28,6 +28,7 @@ import (
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/progress"
"github.com/docker/compose-cli/cli/cmd"
"github.com/docker/compose-cli/cli/formatter"
"github.com/compose-spec/compose-go/types"
@ -178,14 +179,18 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
}()
err = c.ComposeService().Start(ctx, project, compose.StartOptions{
Attach: queue,
Attach: func(event compose.ContainerEvent) {
queue <- event
},
})
if err != nil {
return err
}
_, err = printer.run(ctx, opts.cascadeStop, opts.exitCodeFrom, stopFunc)
// FIXME os.Exit
exitCode, err := printer.run(ctx, opts.cascadeStop, opts.exitCodeFrom, stopFunc)
if exitCode != 0 {
return cmd.ExitCodeError{ExitCode: exitCode}
}
return err
}

28
cli/cmd/exit.go Normal file
View file

@ -0,0 +1,28 @@
/*
Copyright 2020 Docker Compose CLI authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import "strconv"
// ExitCodeError reports an exit code set by command.
type ExitCodeError struct {
ExitCode int
}
func (e ExitCodeError) Error() string {
return strconv.Itoa(e.ExitCode)
}