mirror of
https://github.com/containers/podman.git
synced 2025-06-17 06:57:43 +08:00
use boolreport for containerexists response
in the case of exists, use a boolreport structure so that responses can be consistent pointer and error Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -29,11 +29,11 @@ func init() {
|
||||
}
|
||||
|
||||
func exists(cmd *cobra.Command, args []string) error {
|
||||
exists, err := registry.ContainerEngine().ContainerExists(context.Background(), args[0])
|
||||
response, err := registry.ContainerEngine().ContainerExists(context.Background(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exists {
|
||||
if !response.Value {
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
|
@ -13,3 +13,7 @@ type WaitReport struct {
|
||||
Error error
|
||||
ExitCode int32
|
||||
}
|
||||
|
||||
type BoolReport struct {
|
||||
Value bool
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
type ContainerEngine interface {
|
||||
ContainerDelete(ctx context.Context, opts ContainerDeleteOptions) (*ContainerDeleteReport, error)
|
||||
ContainerPrune(ctx context.Context) (*ContainerPruneReport, error)
|
||||
ContainerExists(ctx context.Context, nameOrId string) (bool, error)
|
||||
ContainerExists(ctx context.Context, nameOrId string) (*BoolReport, error)
|
||||
ContainerWait(ctx context.Context, namesOrIds []string, options WaitOptions) ([]WaitReport, error)
|
||||
PodDelete(ctx context.Context, opts PodPruneOptions) (*PodDeleteReport, error)
|
||||
PodPrune(ctx context.Context) (*PodPruneReport, error)
|
||||
|
@ -12,12 +12,12 @@ import (
|
||||
)
|
||||
|
||||
// TODO: Should return *entities.ContainerExistsReport, error
|
||||
func (ic *ContainerEngine) ContainerExists(ctx context.Context, nameOrId string) (bool, error) {
|
||||
func (ic *ContainerEngine) ContainerExists(ctx context.Context, nameOrId string) (*entities.BoolReport, error) {
|
||||
_, err := ic.Libpod.LookupContainer(nameOrId)
|
||||
if err != nil && errors.Cause(err) != define.ErrNoSuchCtr {
|
||||
return false, err
|
||||
return nil, err
|
||||
}
|
||||
return err == nil, nil
|
||||
return &entities.BoolReport{Value: err == nil}, nil
|
||||
}
|
||||
|
||||
func (ic *ContainerEngine) ContainerWait(ctx context.Context, namesOrIds []string, options entities.WaitOptions) ([]entities.WaitReport, error) {
|
||||
|
@ -7,8 +7,9 @@ import (
|
||||
"github.com/containers/libpod/pkg/domain/entities"
|
||||
)
|
||||
|
||||
func (ic *ContainerEngine) ContainerExists(ctx context.Context, nameOrId string) (bool, error) {
|
||||
return containers.Exists(ctx, nameOrId)
|
||||
func (ic *ContainerEngine) ContainerExists(ctx context.Context, nameOrId string) (*entities.BoolReport, error) {
|
||||
exists, err := containers.Exists(ctx, nameOrId)
|
||||
return &entities.BoolReport{Value: exists}, err
|
||||
}
|
||||
|
||||
func (ic *ContainerEngine) ContainerWait(ctx context.Context, namesOrIds []string, options entities.WaitOptions) ([]entities.WaitReport, error) {
|
||||
|
Reference in New Issue
Block a user