@@ -586,13 +586,17 @@ const commandNotFound = (argv, partialMatches) => {
586
586
context : exports . currentContext ( )
587
587
} )
588
588
589
- const error = partialMatches ? formatPartialMatches ( partialMatches ) : new Error ( commandNotFoundMessage )
589
+ // filter out any partial matches without usage info
590
+ const availablePartials = ( partialMatches || [ ] ) . filter ( ( { options} ) => options . usage ) ,
591
+ anyPartials = availablePartials . length > 0
592
+
593
+ const error = anyPartials ? formatPartialMatches ( availablePartials ) : new Error ( commandNotFoundMessage )
590
594
error . code = 404
591
595
592
596
// to allow for programmatic use of the partial matches, e.g. for tab completion
593
- if ( partialMatches ) {
594
- error . partialMatches = partialMatches . map ( _ => ( { command : _ . route . split ( '/' ) . slice ( 1 ) . join ( ' ' ) ,
595
- usage : _ . options && _ . options . usage } ) )
597
+ if ( anyPartials ) {
598
+ error . partialMatches = availablePartials . map ( _ => ( { command : _ . route . split ( '/' ) . slice ( 1 ) . join ( ' ' ) ,
599
+ usage : _ . options && _ . options . usage } ) )
596
600
}
597
601
598
602
throw error
@@ -608,12 +612,12 @@ const commandNotFound = (argv, partialMatches) => {
608
612
* command completions to what they typed.
609
613
*
610
614
*/
611
- const formatPartialMatches = matches => {
615
+ const formatPartialMatches = partialMatches => {
612
616
return new ( require ( './usage-error' ) ) ( {
613
617
message : commandNotFoundMessage ,
614
618
usage : {
615
619
header : commandNotFoundMessageWithPartialMatches ,
616
- available : matches . map ( ( { options} ) => options . usage ) . filter ( x => x )
620
+ available : partialMatches . map ( ( { options} ) => options . usage )
617
621
}
618
622
} , { noBreadcrumb : true , noHide : true } )
619
623
}
0 commit comments