Files
console/input/chain.go
andrey 4fdeb73e8a
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
add value vithh error (#1)
Co-authored-by: andrey1s <andrey@4devs.pro>
Reviewed-on: #1
Co-authored-by: andrey <andrey@4devs.io>
Co-committed-by: andrey <andrey@4devs.io>
2022-09-18 21:37:25 +03:00

45 lines
760 B
Go

package input
import (
"context"
"fmt"
"gitoa.ru/go-4devs/console/input/value"
)
func Chain(c ...Input) Input {
return chain(c)
}
type chain []Input
func (c chain) Option(ctx context.Context, name string) value.Value {
for _, in := range c {
if val := in.Option(ctx, name); !value.IsEmpty(val) {
return val
}
}
return value.Empty()
}
func (c chain) Argument(ctx context.Context, name string) value.Value {
for _, in := range c {
if val := in.Argument(ctx, name); !value.IsEmpty(val) {
return val
}
}
return value.Empty()
}
func (c chain) Bind(ctx context.Context, def *Definition) error {
for _, input := range c {
if err := input.Bind(ctx, def); err != nil {
return fmt.Errorf("%T:%w", input, err)
}
}
return nil
}