Revert UsageOnMissing.

This was breaking UsageOnMissing() when combined with validation of
positional arguments, in that it was allowing positional arguments to be
omitted. It also broke UsageOnMissing() somehow so that it did not work.
This commit is contained in:
Alec Thomas
2020-10-27 17:32:34 +11:00
parent 73064c7b8f
commit 097bba54ec
4 changed files with 15 additions and 58 deletions
+7 -7
View File
@@ -683,14 +683,8 @@ func (c *Context) Run(binds ...interface{}) (err error) {
defer catch(&err)
node := c.Selected()
if node == nil {
if c.Kong.usageOnMissing {
return c.PrintUsage(false)
}
return fmt.Errorf("no command selected")
}
if c.Kong.usageOnMissing && isMissingChildError(c.Error) {
return c.PrintUsage(false)
}
return c.RunNode(node, binds...)
}
@@ -759,7 +753,13 @@ func checkMissingChildren(node *Node) error {
return nil
}
return newMissingChildError(missing)
if len(missing) > 5 {
missing = append(missing[:5], "...")
}
if len(missing) == 1 {
return fmt.Errorf("expected %s", missing[0])
}
return fmt.Errorf("expected one of %s", strings.Join(missing, ", "))
}
// If we're missing any positionals and they're required, return an error.