MCPcopy Create free account
hub / github.com/alecthomas/kong / validatePositionalArguments

Function validatePositionalArguments

build.go:228–248  ·  view source on GitHub ↗
(node *Node)

Source from the content-addressed store, hash-verified

226}
227
228func validatePositionalArguments(node *Node) error {
229 var last *Value
230 for i, curr := range node.Positional {
231 if last != nil {
232 // Scan through argument positionals to ensure optional is never before a required.
233 if !last.Required && curr.Required {
234 return fmt.Errorf("%s: required %q cannot come after optional %q", node.FullPath(), curr.Name, last.Name)
235 }
236
237 // Cumulative argument needs to be last.
238 if last.IsCumulative() {
239 return fmt.Errorf("%s: argument %q cannot come after cumulative %q", node.FullPath(), curr.Name, last.Name)
240 }
241 }
242
243 last = curr
244 curr.Position = i
245 }
246
247 return nil
248}
249
250func buildChild(k *Kong, node *Node, typ NodeType, v reflect.Value, ft reflect.StructField, fv reflect.Value, tag *Tag, name string, seenFlags map[string]bool) error {
251 child, err := buildNode(k, fv, typ, newEmptyTag(), seenFlags)

Callers 1

buildNodeFunction · 0.85

Calls 3

IsCumulativeMethod · 0.95
ErrorfMethod · 0.80
FullPathMethod · 0.80

Tested by

no test coverage detected