@@ -586,13 +586,17 @@ const commandNotFound = (argv, partialMatches) => {
586586 context : exports . currentContext ( )
587587 } )
588588
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 )
590594 error . code = 404
591595
592596 // 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 } ) )
596600 }
597601
598602 throw error
@@ -608,12 +612,12 @@ const commandNotFound = (argv, partialMatches) => {
608612 * command completions to what they typed.
609613 *
610614 */
611- const formatPartialMatches = matches => {
615+ const formatPartialMatches = partialMatches => {
612616 return new ( require ( './usage-error' ) ) ( {
613617 message : commandNotFoundMessage ,
614618 usage : {
615619 header : commandNotFoundMessageWithPartialMatches ,
616- available : matches . map ( ( { options} ) => options . usage ) . filter ( x => x )
620+ available : partialMatches . map ( ( { options} ) => options . usage )
617621 }
618622 } , { noBreadcrumb : true , noHide : true } )
619623}
0 commit comments