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:
-rwxr-xr-xcli.js32
-rw-r--r--lib/activate.js4
-rw-r--r--lib/adduser.js1
-rw-r--r--lib/autoremove.js5
-rw-r--r--lib/build.js1
-rw-r--r--lib/bundle.js8
-rw-r--r--lib/cache.js7
-rw-r--r--lib/config.js9
-rw-r--r--lib/deactivate.js2
-rw-r--r--lib/help.js74
-rw-r--r--lib/install.js10
-rw-r--r--lib/link.js2
-rw-r--r--lib/ls.js2
-rw-r--r--lib/owner.js11
-rw-r--r--lib/publish.js6
-rw-r--r--lib/rebuild.js2
-rw-r--r--lib/restart.js2
-rw-r--r--lib/start.js2
-rw-r--r--lib/stop.js1
-rw-r--r--lib/tag.js15
-rw-r--r--lib/test.js1
-rw-r--r--lib/uninstall.js3
-rw-r--r--lib/unpublish.js5
-rw-r--r--lib/update-dependents.js4
-rw-r--r--lib/update.js2
-rw-r--r--lib/view.js1
26 files changed, 160 insertions, 52 deletions
diff --git a/cli.js b/cli.js
index af15085e0..5ebc0fe3a 100755
--- a/cli.js
+++ b/cli.js
@@ -26,7 +26,7 @@ var fs = require("./lib/utils/graceful-fs")
log.verbose(argv, "cli")
while (arg = argv.shift()) {
- if (!key && (arg === "-h" || arg === "-?")) arg = "--help"
+ if (!key && (arg.match(/-+[h?]/i))) arg = "--usage"
if (!command && (npm.commands.hasOwnProperty(arg))) {
if (key) {
conf[key] = true
@@ -36,7 +36,7 @@ while (arg = argv.shift()) {
} else if (!flagsDone && arg.substr(0, 2) === "--") {
if (key) conf[key] = true
key = arg.substr(2)
- if (key === "help") conf[key] = true, key = null
+ if (key === "usage") conf[key] = true, key = null
flagsDone = (key === "")
} else if (key) {
conf[key] = arg
@@ -68,24 +68,17 @@ process.on("exit", function () { if (!itWorked) log.win("not ok") })
var itWorked = false
-if (!command && !conf.help) {
- if (!printVersion) {
- // npm.commands.help([arglist.join(" ")])
- if (arglist.length) log.error(arglist, "unknown command")
- sys.error( "What do you want me to do?\n\n"
- + "Usage:\n"
- + " npm [flags] <command> [args]\n"
- + "Check 'npm help' for more information\n\n"
- )
- exit(1)
- } else itWorked = true
-} else {
+
+if (!command && !printVersion) conf.usage = true
+
+if (printVersion) itWorked = true
+else {
+ if (conf.usage && command !== "help") {
+ arglist.unshift(command)
+ command = "help"
+ }
ini.resolveConfigs(conf, function (er) {
if (er) return errorHandler(er)
- if (npm.config.get("help") && command !== "help") {
- arglist.unshift(command)
- command = "help"
- }
npm.config.set("root", ini.get("root"))
npm.commands[command](arglist, errorHandler)
})
@@ -111,6 +104,9 @@ function errorHandler (er) {
,"or email it to <npm-@googlegroups.com>"
].join("\n"))
} else {
+ if (npm.commands[command].usage) {
+ log.error(npm.commands[command].usage)
+ }
log.error(["try running: 'npm help "+command+"'"
,"Report this *entire* log at <http://github.com/isaacs/npm/issues>"
,"or email it to <npm-@googlegroups.com>"
diff --git a/lib/activate.js b/lib/activate.js
index 04327fcbe..d41268fdf 100644
--- a/lib/activate.js
+++ b/lib/activate.js
@@ -22,11 +22,15 @@ var mkdir = require("./utils/mkdir-p")
module.exports = activate
+activate.usage =
+ "Usage: npm activate <name>@<version> [<name>@<version> ...]"
+
function activate (args, cb) {
// make sure package and version exists.
// If there's already an active version, then deactivate it.
// first, link .npm/{pkg}/{version} to .npm/{pkg}/{active}
// then, link the things in the root without a version to the active one.
+ if (!args.length) return cb(new Error(activate.usage))
asyncMap(args, preActivate, function (er, data) {
log.silly(args, "preActivate over")
if (er) return cb(er)
diff --git a/lib/adduser.js b/lib/adduser.js
index 69b097bee..882536cb3 100644
--- a/lib/adduser.js
+++ b/lib/adduser.js
@@ -13,6 +13,7 @@ try {
crypto = process.binding("crypto") && require("crypto")
} catch (ex) {}
+adduser.usage = "npm adduser\nThen enter stuff at the prompts"
function adduser (args, cb) {
if (!crypto) return cb(new Error(
diff --git a/lib/autoremove.js b/lib/autoremove.js
index 240e00ed0..90860da54 100644
--- a/lib/autoremove.js
+++ b/lib/autoremove.js
@@ -5,4 +5,9 @@ module.exports = autoremove
// as auto-removeable and don't have any dependents.
// Normally just triggered by an install of a newer dependency.
+autoremove.usage =
+ "npm autoremove [<pkg>[@<version>] [<pkg>[@<version>]] ...]"
+function autoremove (args, cb) {
+ return cb(new Error("Not implemented"))
+}
diff --git a/lib/build.js b/lib/build.js
index 7dd11f781..a47058cce 100644
--- a/lib/build.js
+++ b/lib/build.js
@@ -32,6 +32,7 @@ var npm = require("../npm")
, exec = require("./utils/exec")
module.exports = build
+build.usage = "npm build <folder>"
// pkg is either a "package" folder, or a package.json data obj, or an
// object that has the package.json data on the _data member.
diff --git a/lib/bundle.js b/lib/bundle.js
index f299f3cf7..4053e60f3 100644
--- a/lib/bundle.js
+++ b/lib/bundle.js
@@ -9,18 +9,18 @@ var npm = require("../npm")
, mkdir = require("./utils/mkdir-p")
, fs = require("./utils/graceful-fs")
+bundle.usage = "npm bundle <location> [<pkg>]"
+
function bundle (args, cb) {
log(args, "bundle")
var location = args.shift()
, pkg = args.shift() || "."
- , usage = "Usage: npm bundle <location> [<pkg>]\n"
- + "(<pkg> defaults to '.')"
- if (!location) return cb(new Error(usage))
+ if (!location) return cb(new Error(bundle.usage))
if (location.charAt(0) !== "/") {
location = path.join(process.cwd(), location)
}
mkdir(location, function (er) {
- if (er) return cb(new Error(usage))
+ if (er) return cb(new Error(bundle.usage))
npm.config.set("root", location)
npm.config.set("binroot", null)
npm.config.set("manroot", null)
diff --git a/lib/cache.js b/lib/cache.js
index bc0c9e921..57cf82eb9 100644
--- a/lib/cache.js
+++ b/lib/cache.js
@@ -18,6 +18,13 @@ var mkdir = require("./utils/mkdir-p")
, path = require("path")
, sys = require("sys")
+cache.usage = "npm cache add <tarball file>"
+ + "\nnpm cache add <folder>"
+ + "\nnpm cache add <tarball url>"
+ + "\nnpm cache add <name> <version>"
+ + "\nnpm cache ls [<path>]"
+ + "\nnpm cache clean [<pkg> [<version>]]"
+
function cache (args, cb) {
var cmd = args.shift()
switch (cmd) {
diff --git a/lib/config.js b/lib/config.js
index da546c26e..adcf3f28f 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -1,6 +1,11 @@
module.exports = config
+config.usage = "npm config set <key> <value> [--global]"
+ + "\nnpm config get <key>"
+ + "\nnpm config delete <key>"
+ + "\nnpm config list"
+
var ini = require("./utils/ini")
, log = require("./utils/log")
, npm = require("../npm")
@@ -58,7 +63,5 @@ function list (cb) {
}
function unknown (action, cb) {
- console.error("Usage:")
- console.error(" npm config [ ls | get <key> | set <key> <val> | delete <key> ]")
- cb()
+ cb("Usage:\n" + config.usage)
}
diff --git a/lib/deactivate.js b/lib/deactivate.js
index 76ccaf2c9..6b9643f84 100644
--- a/lib/deactivate.js
+++ b/lib/deactivate.js
@@ -13,6 +13,8 @@ var mkdir = require("./utils/mkdir-p")
module.exports = deactivate
+deactivate.usage = "npm deactivate <pkg>"
+
function deactivate (args, cb) {
var rb = npm.ROLLBACK
npm.ROLLBACK = true
diff --git a/lib/help.js b/lib/help.js
index 1e1647c2d..615fbb0d0 100644
--- a/lib/help.js
+++ b/lib/help.js
@@ -2,18 +2,74 @@
var fs = require("./utils/graceful-fs")
, path = require("path")
, exec = require("./utils/exec")
+ , npm = require("../npm")
module.exports = help
function help (args, cb) {
- var section = args.shift() || "help"
- fs.stat(path.join(__dirname, "../man1/"+section+".1"), function (e, o) {
- if (e) return cb(new Error("Help section not found: "+section))
- // function exec (cmd, args, env, takeOver, cb) {
- var manpath = path.join(__dirname, "..")
- , env = {}
- Object.keys(process.env).forEach(function (i) { env[i] = process.env[i] })
- env.MANPATH = manpath
- exec("man", [section], env, true, cb)
+ var section = args.shift()
+ if (section) {
+ if ( npm.config.get("usage")
+ && npm.commands[section]
+ && npm.commands[section].usage
+ ) {
+ npm.config.set("loglevel", "silent")
+ console.log(npm.commands[section].usage)
+ return cb()
+ }
+ return fs.stat
+ ( path.join(__dirname, "../man1/"+section+".1")
+ , function (e, o) {
+ if (e) return cb(new Error("Help section not found: "+section))
+ // function exec (cmd, args, env, takeOver, cb) {
+ var manpath = path.join(__dirname, "..")
+ , env = {}
+ Object.keys(process.env).forEach(function (i) { env[i] = process.env[i] })
+ env.MANPATH = manpath
+ exec("man", [section], env, true, cb)
+ }
+ )
+ } else fs.readdir(path.join(__dirname, "../man1/"), function (er, sections) {
+ npm.config.set("loglevel", "silent")
+ console.log
+ (["\nUsage: npm <command>"
+ , ""
+ , "where <command> is one of:"
+ , " "+wrap(Object.keys(npm.commands))
+ , ""
+ , "Specify configs in the ini-formatted file at "+npm.config.get("userconfig")
+ , "or on the command line via: npm <command> --key value"
+ , "Config info can be by running: npm help config"
+ , ""
+ , "Help usage: npm help <section>"
+ , ""
+ , "where <section> is one of:"
+ , (er && er.message)
+ || (" " + wrap(
+ sections
+ .filter(function (s) { return s.match(/\.1$/) })
+ .map(function (s) { return s.replace(/\.1$/, '')})
+ ))
+ , ""
+ , "Even more help at: npm help help"
+ ].join("\n"))
+ cb(er)
})
}
+
+function wrap (arr) {
+ var out = ['']
+ , l = 0
+ arr.sort(function (a,b) { return a<b?-1:1 })
+ .forEach(function (c) {
+ if (out[l].length + c.length + 2 < 60) {
+ out[l] += ', '+c
+ } else {
+ out[l++] += ','
+ out[l] = c
+ }
+ })
+ return out.join("\n ").substr(2)
+}
+
+
diff --git a/lib/install.js b/lib/install.js
index b11785619..5c78d2bcc 100644
--- a/lib/install.js
+++ b/lib/install.js
@@ -13,6 +13,16 @@
module.exports = install
+install.usage = "npm install <tarball file>"
+ + "\nnpm install <tarball url>"
+ + "\nnpm install <folder>"
+ + "\nnpm install <pkg>"
+ + "\nnpm install <pkg>@<tag>"
+ + "\nnpm install <pkg>@<version>"
+ + "\nnpm install <pkg>@<version range>"
+ + "\n\nCan specify one or more: npm install ./foo.tgz bar@stable /some/folder"
+ + "\nInstalls '.' if no argument supplied"
+
var registry = require("./utils/registry")
, npm = require("../npm")
, readInstalled = require("./utils/read-installed")
diff --git a/lib/link.js b/lib/link.js
index 3ba578107..70a99c81f 100644
--- a/lib/link.js
+++ b/lib/link.js
@@ -19,7 +19,7 @@ try {
} catch (ex) {}
module.exports = link
-
+link.usage = "npm link <folder>"
function link (args, cb) {
if (!crypto) return cb(new Error(
"You must compile node with ssl support to use the link feature"))
diff --git a/lib/ls.js b/lib/ls.js
index 3ac498518..9ddb5b944 100644
--- a/lib/ls.js
+++ b/lib/ls.js
@@ -9,6 +9,8 @@ var npm = require("../npm")
, registry = require("./utils/registry")
, semver = require("./utils/semver")
+ls.usage = "npm ls [some search terms ...]"
+
function ls (args, cb) {
readInstalled([], function (er, installed) {
if (er) return cb(er)
diff --git a/lib/owner.js b/lib/owner.js
index 718a6f5e3..5975d23ec 100644
--- a/lib/owner.js
+++ b/lib/owner.js
@@ -1,11 +1,10 @@
-/*
-npm owner add <username> <pkg>
-npm owner rm <username> <pkg>
-npm owner ls <pkg>
-*/
module.exports = owner
+owner.usage = "npm owner add <username> <pkg>"
+ + "\nnpm owner rm <username> <pkg>"
+ + "\nnpm owner ls <pkg>"
+
var registry = require("./utils/registry")
, get = registry.request.GET
, put = registry.request.PUT
@@ -91,5 +90,5 @@ function mutate (pkg, user, mutation, cb) {
}
function unknown (action, cb) {
- cb(new Error("Unrecognized owner command "+action))
+ cb("Usage: \n"+owner.usage)
}
diff --git a/lib/publish.js b/lib/publish.js
index 0c7481999..7c78b2988 100644
--- a/lib/publish.js
+++ b/lib/publish.js
@@ -5,13 +5,17 @@ var npm = require("../npm")
, registry = require("./utils/registry")
, log = require("./utils/log")
+publish.usage = "npm publish <tarball>"
+ + "\nnpm publish <folder>"
+ + "\n\nPublishes '.' if no argument supplied"
+
function publish (args, cb) {
if (args.length === 0) args = ["."]
log.verbose(args, "publish")
npm.commands.cache.add(args[0], args[1], function (er, data) {
if (er) return cb(er)
log.verbose(data, "publish")
- if (!data) return cb(new Error("no data!?"))
+ if (!data) return cb(new Error("no package.json file found"))
registry.publish(data, cb)
})
}
diff --git a/lib/rebuild.js b/lib/rebuild.js
index c7feffedb..8f393e880 100644
--- a/lib/rebuild.js
+++ b/lib/rebuild.js
@@ -12,6 +12,8 @@ var readInstalled = require("./utils/read-installed")
, chain = require("./utils/chain")
, readJson = require("./utils/read-json")
+rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]"
+
function rebuild (args, cb) {
log.verbose(args, "rebuild")
lookupArgs(args, function (er, args) {
diff --git a/lib/restart.js b/lib/restart.js
index c87d21b6b..426e5789b 100644
--- a/lib/restart.js
+++ b/lib/restart.js
@@ -7,6 +7,8 @@ var lifecycle = require("./utils/lifecycle")
, restartCmd = lifecycle.cmd("restart", true)
, log = require("./utils/log")
+restart.usage = "npm restart <name>[@<version>] [<name>[@<version>] ...]"
+
function restart (args, cb) {
restartCmd(args, function (er) {
if (!er) return cb()
diff --git a/lib/start.js b/lib/start.js
index a0c0a6e1b..070a1ad51 100644
--- a/lib/start.js
+++ b/lib/start.js
@@ -1,2 +1,4 @@
+
module.exports = require("./utils/lifecycle").cmd("start")
+module.exports.usage = "npm start <name>[@<version>] [<name>[@<version>] ...]" \ No newline at end of file
diff --git a/lib/stop.js b/lib/stop.js
index dc8c3fa22..2e3a42e4a 100644
--- a/lib/stop.js
+++ b/lib/stop.js
@@ -1,2 +1,3 @@
module.exports = require("./utils/lifecycle").cmd("stop")
+module.exports.usage = "npm stop <name>[@<version>] [<name>[@<version>] ...]"
diff --git a/lib/tag.js b/lib/tag.js
index 0a3bb8be9..e50b97092 100644
--- a/lib/tag.js
+++ b/lib/tag.js
@@ -1,14 +1,15 @@
-// npm tag <project> <version> <tag>
// turns out tagging isn't very complicated
// all the smarts are in the couch.
-module.exports = function (args, cb) {
- var thing = args.shift().split("@")
+module.exports = tag
+tag.usage = "npm tag <project>@<version> <tag>"
+
+function tag (args, cb) {
+ var thing = (args.shift() || "").split("@")
, project = thing.shift()
, version = thing.join("@")
- , tag = args.shift()
- if (!project || !version || !tag) return cb(new Error(
- "Usage: npm tag <project>@<version> <tag>"))
- require("./utils/registry").tag(project, version, tag, cb)
+ , t = args.shift()
+ if (!project || !version || !t) return cb("Usage:\n"+tag.usage)
+ require("./utils/registry").tag(project, version, t, cb)
}
diff --git a/lib/test.js b/lib/test.js
index c24472a5a..20a0e6070 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -1,2 +1,3 @@
module.exports = require("./utils/lifecycle").cmd("test")
+module.exports.usage = "npm test <name>[@<version>] [<name>[@<version>] ...]"
diff --git a/lib/uninstall.js b/lib/uninstall.js
index c38419b35..80dc8ad90 100644
--- a/lib/uninstall.js
+++ b/lib/uninstall.js
@@ -5,6 +5,9 @@
module.exports = uninstall
+uninstall.usage = "npm uninstall <name>[@<version> [<name>[@<version>] ...]"
+ + "\nnpm rm <name>[@<version> [<name>[@<version>] ...]"
+
var rm = require("./utils/rm-rf")
, fs = require("./utils/graceful-fs")
, log = require("./utils/log")
diff --git a/lib/unpublish.js b/lib/unpublish.js
index cace1ba8e..b72ee82eb 100644
--- a/lib/unpublish.js
+++ b/lib/unpublish.js
@@ -4,11 +4,12 @@ module.exports = unpublish
var registry = require("./utils/registry")
, log = require("./utils/log")
+unpublish.usage = "npm unpublish <project>[@<version>]"
+
function unpublish (args, cb) {
var thing = args.shift().split("@")
, project = thing.shift()
, version = thing.join("@")
- if (!project) return cb(new Error(
- "Usage: npm unpublish <project>@<version>"))
+ if (!project) return cb("Usage:\n"+unpublish.usage)
registry.unpublish(project, version, cb)
}
diff --git a/lib/update-dependents.js b/lib/update-dependents.js
index 00b1ecd07..36e7a26fb 100644
--- a/lib/update-dependents.js
+++ b/lib/update-dependents.js
@@ -2,7 +2,7 @@
This command is plumbing.
-npm update-deps <pkg>
+npm update-dependents <pkg>
For each other version of pkg, for each dependent in other
version's dependents folder, if the new version would satisfy the
@@ -15,6 +15,8 @@ If no dependents are left, then remove old version
module.exports = updateDependents
+updateDependents.usage = "npm update-dependents <pkg>"
+
var readInstalled = require("./utils/read-installed")
, path = require("path")
, npm = require("../npm")
diff --git a/lib/update.js b/lib/update.js
index 0c096fd84..c76a2d857 100644
--- a/lib/update.js
+++ b/lib/update.js
@@ -33,6 +33,8 @@ after installation
module.exports = update
+update.usage = "npm update [pkg]"
+
var readInstalled = require("./utils/read-installed")
, chain = require("./utils/chain")
, log = require("./utils/log")
diff --git a/lib/view.js b/lib/view.js
index 3498d51fd..b16e81622 100644
--- a/lib/view.js
+++ b/lib/view.js
@@ -1,6 +1,7 @@
// npm view [pkg [pkg ...]]
module.exports = view
+view.usage = "npm view [pkg [pkg ...]]"
var registry = require("./utils/registry")
, ini = require("./utils/ini-parser")