Documentation
¶
Overview ¶
Package arity parses a small specification language describing how many positional arguments a command may accept.
Specifications are read from textual configuration through Arity.UnmarshalText or ArityFunc.UnmarshalText. See those methods for the accepted grammar.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadArity indicates a command received a number of positional arguments // outside the range permitted by an [ArityFunc]. ErrBadArity = errors.New("bad arity") // ErrEmpty indicates the specification contained no terms. ErrEmpty = errors.New("empty arity specification") // ErrSyntax indicates a term was not a recognized arity expression. ErrSyntax = errors.New("invalid arity syntax") // ErrNegative indicates a term contained a negative bound, which cannot be // an argument count. ErrNegative = errors.New("negative arity bound") // ErrEmptyRange indicates a term described a range containing no values. ErrEmptyRange = errors.New("empty arity range") // ErrOverlap indicates two terms described overlapping ranges. ErrOverlap = errors.New("overlapping arity ranges") )
Functions ¶
This section is empty.
Types ¶
type Arity ¶
type Arity struct {
// contains filtered or unexported fields
}
Arity describes the set of permitted argument counts parsed from a specification.
func (Arity) Contains ¶
Contains reports whether n is a permitted argument count. The zero-value Arity permits no counts.
func (Arity) String ¶
String returns a human-readable description of the permitted argument counts, such as "at most 1 argument" or, for disjoint ranges, "exactly 1 argument, or at least 3 arguments". The zero-value Arity returns an empty string.
func (*Arity) UnmarshalText ¶
UnmarshalText parses an arity specification and configures the Arity to permit the described argument counts.
A specification is a comma-separated list of terms. Each term is an exact count ("3"), a comparison (">3", ">=3", "<3", "<=3"), or a range with an exclusive ("1..3") or inclusive ("1..=3") upper bound. Terms may touch but must not overlap.
It returns ErrEmpty, ErrSyntax, ErrNegative, ErrEmptyRange, or ErrOverlap when the specification is invalid.
type ArityFunc ¶
ArityFunc validates that a command received a permitted number of positional arguments. It satisfies cobra's positional-argument validator signature.
func (*ArityFunc) UnmarshalText ¶
UnmarshalText parses an arity specification, using the same grammar and returning the same errors as Arity.UnmarshalText. On success it configures the ArityFunc to report a wrapped ErrBadArity when a command receives an argument count outside the permitted range.