diff options
author | isaacs <i@izs.me> | 2010-04-25 05:58:27 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-04-25 05:58:44 +0400 |
commit | 108a51ea53cdfcf68af31957c2e9afc6ddc3762f (patch) | |
tree | 7180beb8c5f58e4330d054750d0c40c6f30af066 /cli.js | |
parent | 228638e6074e5d5366b4b154cc5b5e9ed0340134 (diff) |
Update the way that the npm cli commands work so that it's a bit more robust and possible to handle errors a bit more nicely. Also, lots of comma-first goodness.
Diffstat (limited to 'cli.js')
-rwxr-xr-x | cli.js | 41 |
1 files changed, 22 insertions, 19 deletions
@@ -1,8 +1,5 @@ #!/usr/bin/env node -// usage: -// npm [global options] command [command args] - // don't assume that npm is installed in any particular spot, since this // might conceivably be a bootstrap attempt. var fs = require("fs") @@ -16,22 +13,35 @@ var fs = require("fs") , argv = process.argv.slice(2) , arg = "" -var parsed = {} + , conf = {} , key - , val -while (arg = argv.shift()) { - if (arg in npm.commands) { - command = arg; - break; - } - -} + , arglist = [] + , command log(sys.inspect(argv), "cli") // add usage onto any existing help documentation. npm.commands.help = usage +while (arg = argv.shift()) { + if (!command && (arg in npm.commands)) command = arg + else if (!key && arg.charAt(0) === "-") key = arg.replace(/^-+/, '') + else if (key) { + conf[key] = arg + key = null + } else arglist.push(arg) +} +if (key) conf[key] = true + +if (!command) command = "help" + +npm.commands[command](arglist, conf, function (er, ok) { + if (er) { + log("failed " + er.message) + throw er + } else log("ok") +}) + function usage () { var out = (arg === "help" ? "puts" : "error"); function p (m) { sys[out](m); return p }; @@ -43,10 +53,3 @@ function usage () { p(" Supported: "+commands) p("[command options] The arguments to pass to the function."); } - -npm.commands[command].apply(npm.commands, argv.concat(function (er, ok) { - if (er) { - log("failed " + er.message); - throw er; - } else log("ok"); -})); |