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
path: root/cli.js
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2010-06-11 22:07:32 +0400
committerisaacs <i@izs.me>2010-06-11 22:08:08 +0400
commit64549948c0b86429be5284f24f656cbdf984c871 (patch)
tree72701e2f918e250b54576f32e847b12768604cd8 /cli.js
parente0701d4a91eb3c73140043a00d25ec1a78c8a6da (diff)
Add an easy way to print the version using npm -v or npm --version
Diffstat (limited to 'cli.js')
-rwxr-xr-xcli.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/cli.js b/cli.js
index 30aebc816..8d9b0efe0 100755
--- a/cli.js
+++ b/cli.js
@@ -19,7 +19,6 @@ var fs = require("fs")
, flagsDone
log(sys.inspect(argv), "cli")
-log(npm.version, "version")
while (arg = argv.shift()) {
if (!command && (arg in npm.commands)) {
@@ -41,9 +40,16 @@ if (key) conf[key] = true
npm.argv = arglist
for (var k in conf) npm.config.set(k, conf[k])
+var vindex = arglist.indexOf("-v")
+ , printVersion = vindex !== -1 || conf.version
+if (printVersion) {
+ sys.puts(npm.version)
+ if (vindex !== -1) arglist.splice(vindex, 1)
+} else log(npm.version, "version")
+
process.addListener("uncaughtException", errorHandler)
-if (!command) {
+if (!command) { if (!printVersion) {
// npm.commands.help([arglist.join(" ")])
if (arglist.length) log(arglist, "unknown command")
sys.error( "What do you want me to do?\n\n"
@@ -52,7 +58,7 @@ if (!command) {
+ "Check 'man npm' or 'man npm-help' for more information\n\n"
+ "This is supposed to happen. "
)
-} else npm.commands[command](arglist, errorHandler)
+}} else npm.commands[command](arglist, errorHandler)
function errorHandler (er) {
if (er) {