diff options
author | isaacs <i@izs.me> | 2010-09-29 04:02:17 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-09-29 04:02:17 +0400 |
commit | 42c6fd209a825e0f5a74663704943272065a414f (patch) | |
tree | f9425603ff929c9c9b591c4826673b1365baf5bc /cli.js | |
parent | 0164a0df44ae573137d43e3a3df84d032e7345bb (diff) |
Print nice short "usage" lines when doing -h, -?, or --help
Diffstat (limited to 'cli.js')
-rwxr-xr-x | cli.js | 32 |
1 files changed, 14 insertions, 18 deletions
@@ -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>" |