Skip to content

Commit

Permalink
fix for buggy "available commands" -- improper handling of no suggest…
Browse files Browse the repository at this point in the history
…ions

Fixes #978
  • Loading branch information
starpit committed May 24, 2018
1 parent 57f1b0d commit a719c43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions app/content/js/command-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,17 @@ const commandNotFound = (argv, partialMatches) => {
context: exports.currentContext()
})

const error = partialMatches ? formatPartialMatches(partialMatches) : new Error(commandNotFoundMessage)
// filter out any partial matches without usage info
const availablePartials = (partialMatches || []).filter(({options}) => options.usage),
anyPartials = availablePartials.length > 0

const error = anyPartials ? formatPartialMatches(availablePartials) : new Error(commandNotFoundMessage)
error.code = 404

// to allow for programmatic use of the partial matches, e.g. for tab completion
if (partialMatches) {
error.partialMatches = partialMatches.map(_ => ({ command: _.route.split('/').slice(1).join(' '),
usage: _.options && _.options.usage }))
if (anyPartials) {
error.partialMatches = availablePartials.map(_ => ({ command: _.route.split('/').slice(1).join(' '),
usage: _.options && _.options.usage }))
}

throw error
Expand All @@ -608,12 +612,12 @@ const commandNotFound = (argv, partialMatches) => {
* command completions to what they typed.
*
*/
const formatPartialMatches = matches => {
const formatPartialMatches = partialMatches => {
return new (require('./usage-error'))({
message: commandNotFoundMessage,
usage: {
header: commandNotFoundMessageWithPartialMatches,
available: matches.map(({options}) => options.usage).filter(x=>x)
available: partialMatches.map(({options}) => options.usage)
}
}, { noBreadcrumb: true, noHide: true })
}
Expand Down
4 changes: 2 additions & 2 deletions app/content/js/usage-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ const format = (message, options={}) => {
cmdCell = row.insertCell(-1),
docsCell = row.insertCell(-1),
cmdPart = span(label),
dirPart = isDir && span('/'),
examplePart = example && span(example, 'left-pad'), // for -p key value, "key value"
dirPart = isDir && label && span('/'),
examplePart = example && span(example, label || dirPart ? 'left-pad' : ''), // for -p key value, "key value"
aliasesPart = aliases && span(undefined, 'deemphasize small-left-pad'),
docsPart = span(docs),
allowedPart = allowed && smaller(span(undefined))
Expand Down

0 comments on commit a719c43

Please sign in to comment.