posh/pkg/command/tree/args.go
2023-03-21 08:13:30 +01:00

26 lines
391 B
Go

package tree
import (
"github.com/foomo/posh/pkg/readline"
"github.com/pkg/errors"
)
type Args []*Arg
func (a Args) Last() *Arg {
if len(a) > 0 {
return a[len(a)-1]
} else {
return nil
}
}
func (a Args) Validate(args readline.Args) error {
for j, arg := range a {
if !arg.Optional && len(args)-1 < j {
return errors.Wrap(ErrMissingArgument, arg.Name)
}
}
return nil
}