Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Cooper <mfncooper@gmail.com>2011-10-03 03:48:13 +0400
committerisaacs <i@izs.me>2011-10-03 04:13:34 +0400
commit7814ae00806530f8c7180bc0ea88c22ceb1d5a64 (patch)
treebad63678a84f1a0f361db94298d8e3eb72fbb31e
parent7ea7f2d6564d21c5a1703bbbc3bd33435b103153 (diff)
New 'bugs' command.
-rw-r--r--doc/api/bugs.md19
-rw-r--r--doc/cli/bugs.md38
-rw-r--r--lib/bugs.js53
-rw-r--r--npm.js3
4 files changed, 112 insertions, 1 deletions
diff --git a/doc/api/bugs.md b/doc/api/bugs.md
new file mode 100644
index 000000000..cc4db8f9e
--- /dev/null
+++ b/doc/api/bugs.md
@@ -0,0 +1,19 @@
+npm-bugs(3) -- Bugs for a package in a web browser maybe
+========================================================
+
+## SYNOPSIS
+
+ npm.commands.bugs(package, callback)
+
+## DESCRIPTION
+
+This command tries to guess at the likely location of a package's
+bug tracker URL, and then tries to open it using the `--browser`
+config param.
+
+Like other commands, the first parameter is an array. This command only
+uses the first element, which is expected to be a package name with an
+optional version number.
+
+This command will launch a browser, so this command may not be the most
+friendly for programmatic use.
diff --git a/doc/cli/bugs.md b/doc/cli/bugs.md
new file mode 100644
index 000000000..2e57cc891
--- /dev/null
+++ b/doc/cli/bugs.md
@@ -0,0 +1,38 @@
+npm-bugs(1) -- Bugs for a package in a web browser maybe
+========================================================
+
+## SYNOPSIS
+
+ npm bugs <pkgname>
+
+## DESCRIPTION
+
+This command tries to guess at the likely location of a package's
+bug tracker URL, and then tries to open it using the `--browser`
+config param.
+
+## CONFIGURATION
+
+### browser
+
+* Default: OS X: `"open"`, others: `"google-chrome"`
+* Type: String
+
+The browser that is called by the `npm bugs` command to open websites.
+
+### registry
+
+* Default: https://registry.npmjs.org/
+* Type: url
+
+The base URL of the npm package registry.
+
+
+## SEE ALSO
+
+* npm-docs(1)
+* npm-view(1)
+* npm-publish(1)
+* npm-registry(1)
+* npm-config(1)
+* npm-json(1)
diff --git a/lib/bugs.js b/lib/bugs.js
new file mode 100644
index 000000000..aed731d64
--- /dev/null
+++ b/lib/bugs.js
@@ -0,0 +1,53 @@
+
+module.exports = bugs
+
+bugs.usage = "npm bugs <pkgname>"
+
+bugs.completion = function (opts, cb) {
+ if (opts.conf.argv.remain.length > 2) return cb()
+ registry.get("/-/short", null, 60000, function (er, list) {
+ return cb(null, list || [])
+ })
+}
+
+var exec = require("./utils/exec.js")
+ , registry = require("./utils/npm-registry-client/index.js")
+ , npm = require("../npm.js")
+ , log = require("./utils/log.js")
+
+function bugs (args, cb) {
+ if (!args.length) return cb(bugs.usage)
+ var n = args[0].split("@").shift()
+ registry.get(n, "latest", 3600, function (er, d) {
+ if (er) return cb(er)
+ var bugs = d.bugs
+ , repo = d.repository || d.repositories
+ if (bugs) {
+ if (typeof bugs === "string") return open(bugs, cb)
+ if (bugs.url) bugs = bugs.url
+ else if (bugs.web) bugs = bugs.web
+ else if (bugs.name && /^http/.test(bugs.name)) bugs = bugs.name
+ else bugs = null
+ if (bugs) return open(bugs, cb)
+ }
+ if (repo) {
+ if (Array.isArray(repo)) repo = repo.shift()
+ if (repo.url) repo = repo.url
+ log.verbose(repo, "repository")
+ if (repo) {
+ return open(repo.replace(/^git(@|:\/\/)/, 'http://')
+ .replace(/\.git$/, '')+"/issues", cb)
+ }
+ }
+ return open("http://search.npmjs.org/#/" + d.name, cb)
+ })
+}
+
+function open (url, cb) {
+ exec(npm.config.get("browser"), [url], log.er(cb,
+ "Failed to open "+url+" in a browser. It could be that the\n"+
+ "'browser' config is not set. Try doing this:\n"+
+ " npm config set browser google-chrome\n"+
+ "or:\n"+
+ " npm config set browser lynx\n"))
+}
diff --git a/npm.js b/npm.js
index 3578ac648..3465f4b22 100644
--- a/npm.js
+++ b/npm.js
@@ -40,7 +40,7 @@ if (process.platform === "win32") {
var cb = arguments[arguments.length - 1]
if (typeof cb == "function") cb()
}
-
+
// patch rename/renameSync, but this should really be fixed in node
var _fsRename = fs.rename
, _fsPathPatch
@@ -135,6 +135,7 @@ var commandCache = {}
, "edit"
, "explore"
, "docs"
+ , "bugs"
, "faq"
, "root"
, "prefix"