c91e593bfdec5ac620379bb607a1b5f82818939d
[platform/upstream/nodejs.git] / deps / npm / lib / repo.js
1
2 module.exports = repo
3
4 repo.usage = "npm repo <pkgname>"
5
6 repo.completion = function (opts, cb) {
7   if (opts.conf.argv.remain.length > 2) return cb()
8   registry.get("/-/short", 60000, function (er, list) {
9     return cb(null, list || [])
10   })
11 }
12
13 var npm = require("./npm.js")
14   , registry = npm.registry
15   , log = require("npmlog")
16   , opener = require("opener")
17   , github = require('github-url-from-git')
18   , githubUserRepo = require("github-url-from-username-repo")
19
20 function repo (args, cb) {
21   if (!args.length) return cb(repo.usage)
22   var n = args[0].split("@").shift()
23   registry.get(n + "/latest", 3600, function (er, d) {
24     if (er) return cb(er)
25     var r = d.repository;
26     if (!r) return cb(new Error('no repository'));
27     // XXX remove this when npm@v1.3.10 from node 0.10 is deprecated
28     // from https://github.com/isaacs/npm-www/issues/418
29     if (githubUserRepo(r.url))
30       r.url = githubUserRepo(r.url)
31
32     var url = github(r.url)
33     if (!url)
34       return cb(new Error('no repository: could not get url'))
35     opener(url, { command: npm.config.get("browser") }, cb)
36   })
37 }