Skip to content

Commit

Permalink
Fix completion for partial commands
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs authored and ruyadorno committed Jul 29, 2020
1 parent bd080ea commit 0998340
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ completion.usage = 'source <(npm completion)'
var npm = require('./npm.js')
var npmconf = require('./config/core.js')
var configDefs = npmconf.defs
const { aliases, cmdList, plumbing } = require('./config/cmd-list.js')
const aliasNames = Object.keys(aliases)
const fullList = cmdList.concat(aliasNames).filter(c => !plumbing.includes(c))
var configTypes = configDefs.types
var shorthands = configDefs.shorthands
var nopt = require('nopt')
Expand Down Expand Up @@ -121,8 +124,9 @@ function completion (args, cb) {
var parsed = opts.conf =
nopt(configTypes, shorthands, partialWords.slice(0, -1), 0)
// check if there's a command already.
console.error(parsed)
console.error('PARSED', parsed)
var cmd = parsed.argv.remain[1]
console.error('CMD', cmd)
if (!cmd) return cmdCompl(opts, cb)

Object.keys(parsed).forEach(function (k) {
Expand Down Expand Up @@ -244,5 +248,5 @@ function isFlag (word) {

// complete against the npm commands
function cmdCompl (opts, cb) {
return cb(null, npm.fullList)
return cb(null, fullList)
}

0 comments on commit 0998340

Please sign in to comment.