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/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-08-24 01:36:14 +0400
committerisaacs <i@izs.me>2011-08-24 01:38:07 +0400
commitb5b4b86fe7c4781660199c00575b4020ae7ba61d (patch)
treeb664b8811db601d74c78d292ee4042d305395916 /lib
parent6faa022246e1f6676c627be77723b970d6a1ab36 (diff)
Spit out all usages when --long is set
Diffstat (limited to 'lib')
-rw-r--r--lib/help.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/help.js b/lib/help.js
index cc0a3c5a1..cb7b7a458 100644
--- a/lib/help.js
+++ b/lib/help.js
@@ -54,9 +54,11 @@ function help (args, cb) {
( ["\nUsage: npm <command>"
, ""
, "where <command> is one of:"
- , " "+wrap(Object.keys(npm.commands))
+ , npm.config.get("long") ? usages()
+ : " " + wrap(Object.keys(npm.commands))
, ""
, "npm <cmd> -h quick help on <cmd>"
+ , "npm -l display full usage info"
, "npm faq commonly asked questions"
, "npm help <term> search for help on <term>"
, "npm help npm involved overview"
@@ -69,6 +71,26 @@ function help (args, cb) {
})
}
+function usages () {
+ // return a string of <cmd>: <usage>
+ var maxLen = 0
+ return Object.keys(npm.commands).filter(function (c) {
+ return c === npm.deref(c)
+ }).reduce(function (set, c) {
+ set.push([c, npm.commands[c].usage || ""])
+ maxLen = Math.max(maxLen, c.length)
+ return set
+ }, []).map(function (item) {
+ var c = item[0]
+ , usage = item[1]
+ return "\n " + c + (new Array(maxLen - c.length + 2).join(" "))
+ + (usage.split("\n")
+ .join("\n" + (new Array(maxLen + 6).join(" "))))
+ }).join("\n")
+ return out
+}
+
+
function wrap (arr) {
var out = ['']
, l = 0