You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
760 B

4 years ago
package input
import (
"context"
"fmt"
4 years ago
"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
}
}
4 years ago
return value.Empty()
4 years ago
}
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
}
}
4 years ago
return value.Empty()
4 years ago
}
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)
4 years ago
}
}
return nil
}