summaryrefslogtreecommitdiff
path: root/deps/npm/lib/bugs.js
blob: 10300d1e136203dfedcb97dc704fba0d1303ed4e (plain)
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
module.exports = bugs

var log = require('npmlog')
var openUrl = require('./utils/open-url')
var fetchPackageMetadata = require('./fetch-package-metadata.js')
var usage = require('./utils/usage')

bugs.usage = usage(
  'bugs',
  'npm bugs [<pkgname>]'
)

bugs.completion = function (opts, cb) {
  // FIXME: there used to be registry completion here, but it stopped making
  // sense somewhere around 50,000 packages on the registry
  cb()
}

function bugs (args, cb) {
  var n = args.length ? args[0] : '.'
  fetchPackageMetadata(n, '.', {fullMetadata: true}, function (er, d) {
    if (er) return cb(er)

    var url = d.bugs && ((typeof d.bugs === 'string') ? d.bugs : d.bugs.url)
    if (!url) {
      url = 'https://www.npmjs.org/package/' + d.name
    }
    log.silly('bugs', 'url', url)
    openUrl(url, 'bug list available at the following URL', cb)
  })
}