summaryrefslogtreecommitdiff
path: root/deps/npm/lib/utils/completion/users.js
blob: f77312c94e87ea16e05abcd2591c5c78f66f1f32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

module.exports = users

var registry = require("../npm-registry-client/index.js")
  , containsSingleMatch = require("./contains-single-match.js")
  , getCompletions = require("./get-completions.js")
  , log = require("../log.js")

function users (args, index, cb) {
  var name = (args.length + 1 === index) ? args[args.length - 1] : ""
  if (name === undefined) name = ""
  // use up-to 1 day stale cache.  doesn't change much
  log.warn("About to fetch", "users completion")
  registry.get("/-/users", null, 24*60*60, function (er, d) {
    log.warn(d, "userdata")
    log.warn(name, "name")
    if (er) return cb(er)
    var remoteList = Object.keys(d)
      , simpleMatches = getCompletions(name, remoteList)
    return cb(null, simpleMatches)
  })
}