Skip to content

Commit

Permalink
filter after de-array-ifying
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Mar 21, 2011
1 parent 50a8c96 commit e51a8ea
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ function completion (args, cb) {
var cmd = parsed.argv.remain[1]
if (!cmd) return cmdCompl(opts, cb)

Object.keys(parsed).forEach(function (k) {
npm.config.set(k, parsed[k])
})

// at this point, if words[1] is some kind of npm command,
// then complete on it.
// otherwise, do nothing
Expand Down Expand Up @@ -131,16 +135,17 @@ function escape (w) {
// to: "a", "b c", or "d" "e"
function wrapCb (cb, opts) { return function (er, compls) {
if (!Array.isArray(compls)) compls = compls ? [compls] : []
compls = compls.map(function (c) {
if (Array.isArray(c)) c = c.map(escape).join(" ")
else c = escape(c)
return c
})
if (opts.partialWord) compls = compls.filter(function (c) {
return c.indexOf(opts.partialWord) === 0
})
console.error([er && er.stack, compls, opts.partialWord])
if (er || compls.length === 0) return cb(er)
output.write(compls.map(function (c) {
if (Array.isArray(c)) c = c.map(escape).join(" ")
else c = escape(c)
return c
}).join("\n"), stdio.stdoutFD, false, cb)
output.write(compls.join("\n"), stdio.stdoutFD, false, cb)
}}

// the current word has a dash. Return the config names,
Expand Down

0 comments on commit e51a8ea

Please sign in to comment.