Fix incorrect error missing for missing required args.
This commit is contained in:
+7
-1
@@ -518,11 +518,17 @@ func checkMissingFlags(flags []*Flag) error {
|
||||
|
||||
func checkMissingChildren(node *Node) error {
|
||||
missing := []string{}
|
||||
|
||||
missingArgs := []string{}
|
||||
for _, arg := range node.Positional {
|
||||
if arg.Required && !arg.Set {
|
||||
missing = append(missing, strconv.Quote(arg.Summary()))
|
||||
missingArgs = append(missingArgs, arg.Summary())
|
||||
}
|
||||
}
|
||||
if len(missingArgs) > 0 {
|
||||
missing = append(missing, strconv.Quote(strings.Join(missingArgs, " ")))
|
||||
}
|
||||
|
||||
for _, child := range node.Children {
|
||||
if child.Hidden {
|
||||
continue
|
||||
|
||||
@@ -71,7 +71,8 @@ func printCommand(w *helpWriter, app *Application, cmd *Command) {
|
||||
}
|
||||
printNodeDetail(w, cmd)
|
||||
if w.Summary && app.HelpFlag != nil {
|
||||
w.Printf(`Run "%s %s --help" for more information.`, app.Name, cmd.FullPath())
|
||||
w.Print("")
|
||||
w.Printf(`Run "%s --help" for more information.`, cmd.FullPath())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -554,3 +554,15 @@ func TestInterpolationIntoModel(t *testing.T) {
|
||||
require.Equal(t, map[string]bool{"a": true, "b": true, "c": true, "d": true}, flag.EnumMap())
|
||||
require.Equal(t, "One of a,b", flag2.Help)
|
||||
}
|
||||
|
||||
func TestErrorMissingArgs(t *testing.T) {
|
||||
var cli struct {
|
||||
One string `arg:""`
|
||||
Two string `arg:""`
|
||||
}
|
||||
|
||||
p := mustNew(t, &cli)
|
||||
_, err := p.Parse(nil)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, "expected \"<one> <two>\"", err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user