Fix incorrect error missing for missing required args.

This commit is contained in:
Alec Thomas
2018-08-14 21:05:21 +10:00
parent f0bd1294a7
commit ebe508cf46
3 changed files with 21 additions and 2 deletions
+7 -1
View File
@@ -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
+2 -1
View File
@@ -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())
}
}
+12
View File
@@ -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())
}