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:
authorDaijiro Wachi <daijiro.wachi@gmail.com>2016-04-26 23:51:59 +0300
committerRebecca Turner <me@re-becca.org>2016-04-28 03:28:17 +0300
commita53feac2647f7dc4245f1700dfbdd1aba8745672 (patch)
tree71fbd7372083ac6e802e4f01c32c43aded44293d /lib
parent6cfbae403abc3cf690565b09569f71cdd41a8372 (diff)
utils: add usage summary generator
Credit: @watilde Reviewed-By: @iarna PR-URL: https://github.com/npm/npm/pull/12485
Diffstat (limited to 'lib')
-rw-r--r--lib/utils/usage.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/utils/usage.js b/lib/utils/usage.js
new file mode 100644
index 000000000..261d84ee8
--- /dev/null
+++ b/lib/utils/usage.js
@@ -0,0 +1,27 @@
+'use strict'
+var aliases = require('../config/cmd-list').aliases
+
+module.exports = function usage (cmd, txt, opt) {
+ var post = Object.keys(aliases).reduce(function (p, c) {
+ var val = aliases[c]
+ if (val !== cmd) return p
+ return p.concat(c)
+ }, [])
+
+ if (opt || post.length > 0) txt += '\n\n'
+
+ if (post.length === 1) {
+ txt += 'aliase: '
+ txt += post.join(', ')
+ } else if (post.length > 1) {
+ txt += 'aliases: '
+ txt += post.join(', ')
+ }
+
+ if (opt) {
+ if (post.length > 0) txt += '\n'
+ txt += 'common options: ' + opt
+ }
+
+ return txt
+}