diff --git a/app.go b/app.go index 0ad42f2..ef54e85 100644 --- a/app.go +++ b/app.go @@ -130,6 +130,7 @@ func (a *App) list(ctx context.Context) error { if err != nil { return err } + in := &input.Wrap{ Input: a.in, } diff --git a/example/pkg/command/create_user_test.go b/example/pkg/command/create_user_test.go index 7c49ea1..84b74f6 100644 --- a/example/pkg/command/create_user_test.go +++ b/example/pkg/command/create_user_test.go @@ -13,10 +13,10 @@ import ( func TestCreateUser(t *testing.T) { ctx := context.Background() - in := &input.Array{} - in.SetArgument("username", "andrey") buf := bytes.Buffer{} out := output.Buffer(&buf) + in := &input.Array{} + in.SetArgument("username", "andrey") err := console.Run(ctx, command.CreateUser(false), in, out) if err != nil { diff --git a/input/array.go b/input/array.go index 6b34234..72b5b8e 100644 --- a/input/array.go +++ b/input/array.go @@ -58,14 +58,14 @@ func (a *Array) Argument(_ context.Context, name string) value.Value { } func (a *Array) Bind(ctx context.Context, d *Definition) error { - if err := a.bindArguments(ctx, d); err != nil { + if err := a.bindArguments(d); err != nil { return err } - return a.bindOption(ctx, d) + return a.bindOption(d) } -func (a *Array) bindOption(ctx context.Context, def *Definition) error { +func (a *Array) bindOption(def *Definition) error { for _, name := range def.Options() { opt, err := def.Option(name) if err != nil { @@ -77,6 +77,7 @@ func (a *Array) bindOption(ctx context.Context, def *Definition) error { switch { case opt.HasDefault(): a.defaults.SetOption(name, opt.Default) + continue case opt.IsRequired(): return errs.Option(name, errs.ErrRequired) @@ -85,17 +86,17 @@ func (a *Array) bindOption(ctx context.Context, def *Definition) error { } } + a.SetOption(name, v) + if err := opt.Validate(v); err != nil { return errs.Option(name, err) } - - a.SetOption(name, v) } return nil } -func (a *Array) bindArguments(ctx context.Context, def *Definition) error { +func (a *Array) bindArguments(def *Definition) error { for pos, name := range def.Arguments() { arg, err := def.Argument(pos) if err != nil { @@ -107,6 +108,7 @@ func (a *Array) bindArguments(ctx context.Context, def *Definition) error { switch { case arg.HasDefault(): a.defaults.SetArgument(name, arg.Default) + continue case arg.IsRequired(): return errs.Argument(name, errs.ErrRequired) diff --git a/input/value/empty.go b/input/value/empty.go index 1fd329f..d4f09ca 100644 --- a/input/value/empty.go +++ b/input/value/empty.go @@ -4,7 +4,10 @@ import ( "time" ) -var Empty = &empty{} +// nolint: gochecknoglobals +var ( + Empty = &empty{} +) func IsEmpty(v Value) bool { return v == Empty