@@ -32,7 +32,8 @@ func NoArgs(cmd *Command, args []string) error {
3232 return nil
3333}
3434
35- // OnlyValidArgs returns an error if any args are not in the list of ValidArgs.
35+ // OnlyValidArgs returns an error if there are any positional args that are not in
36+ // the `ValidArgs` field of `Command`
3637func OnlyValidArgs (cmd * Command , args []string ) error {
3738 if len (cmd .ValidArgs ) > 0 {
3839 // Remove any description that may be included in ValidArgs.
@@ -41,7 +42,6 @@ func OnlyValidArgs(cmd *Command, args []string) error {
4142 for _ , v := range cmd .ValidArgs {
4243 validArgs = append (validArgs , strings .Split (v , "\t " )[0 ])
4344 }
44-
4545 for _ , v := range args {
4646 if ! stringInSlice (v , validArgs ) {
4747 return fmt .Errorf ("invalid argument %q for %q%s" , v , cmd .CommandPath (), cmd .findSuggestions (args [0 ]))
@@ -86,18 +86,6 @@ func ExactArgs(n int) PositionalArgs {
8686 }
8787}
8888
89- // ExactValidArgs returns an error if
90- // there are not exactly N positional args OR
91- // there are any positional args that are not in the `ValidArgs` field of `Command`
92- func ExactValidArgs (n int ) PositionalArgs {
93- return func (cmd * Command , args []string ) error {
94- if err := ExactArgs (n )(cmd , args ); err != nil {
95- return err
96- }
97- return OnlyValidArgs (cmd , args )
98- }
99- }
100-
10189// RangeArgs returns an error if the number of args is not within the expected range.
10290func RangeArgs (min int , max int ) PositionalArgs {
10391 return func (cmd * Command , args []string ) error {
@@ -119,3 +107,11 @@ func MatchAll(pargs ...PositionalArgs) PositionalArgs {
119107 return nil
120108 }
121109}
110+
111+ // ExactValidArgs returns an error if there are not exactly N positional args OR
112+ // there are any positional args that are not in the `ValidArgs` field of `Command`
113+ //
114+ // Deprecated: use MatchAll(ExactArgs(n), OnlyValidArgs) instead
115+ func ExactValidArgs (n int ) PositionalArgs {
116+ return MatchAll (ExactArgs (n ), OnlyValidArgs )
117+ }
0 commit comments