-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompletion.js
42 lines (35 loc) · 1.37 KB
/
completion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module.exports = completion
completion.usage = "Not intended to be used directly.\n"
+ "See the npm-completion.sh script in the npm "
+ "source directory"
var npm = require("../npm")
, getCompletions = require("./utils/completion/get-completions")
, containsSingleMatch = require("./utils/completion/contains-single-match")
, output = require("./utils/output")
, index = npm.config.get("comp-cword") || process.env.COMP_CWORD
, log = require("./utils/log")
function completion (args, cb_) {
var cmd = args[1] || ""
, complFullList = getCompletions(cmd, npm.fullList, true)
Object.keys(process.env).filter(function (e) {
return e.toUpperCase().match(/^COMP/)
}).forEach(function (e) {
log.warn(e+"="+process.env[e], "completion env")
})
function cb (er, list) {
if (er) return cb_(er)
outputCompletions(list, cb_)
}
if (index > 1 || (complFullList.indexOf(cmd) !== -1 &&
containsSingleMatch(cmd, complFullList))) {
var subargs = args.slice(2)
// TODO: bundle
npm.commands[npm.deref(cmd)].completion(subargs, index, cb)
} else cb(null, complFullList)
}
function outputCompletions (list, cb_) {
var outfd = npm.config.get("outfd")
function cb () { cb_(list.length ? null : "no match found", list) }
log.warn(list, "completion output")
output.write(outfd, list, false, cb)
}