Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit a719c43

Browse files
committed
fix for buggy "available commands" -- improper handling of no suggestions
Fixes #978
1 parent 57f1b0d commit a719c43

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

app/content/js/command-tree.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -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
}

app/content/js/usage-error.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ const format = (message, options={}) => {
354354
cmdCell = row.insertCell(-1),
355355
docsCell = row.insertCell(-1),
356356
cmdPart = span(label),
357-
dirPart = isDir && span('/'),
358-
examplePart = example && span(example, 'left-pad'), // for -p key value, "key value"
357+
dirPart = isDir && label && span('/'),
358+
examplePart = example && span(example, label || dirPart ? 'left-pad' : ''), // for -p key value, "key value"
359359
aliasesPart = aliases && span(undefined, 'deemphasize small-left-pad'),
360360
docsPart = span(docs),
361361
allowedPart = allowed && smaller(span(undefined))

0 commit comments

Comments
 (0)