Browse Source

update lint

pull/2/head
andrey1s 4 years ago
parent
commit
3843a30d85
  1. 1
      app.go
  2. 4
      example/pkg/command/create_user_test.go
  3. 14
      input/array.go
  4. 5
      input/value/empty.go

1
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,
}

4
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 {

14
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)

5
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

Loading…
Cancel
Save