Skip to content

Commit

Permalink
utils: add usage summary generator
Browse files Browse the repository at this point in the history
Credit: @watilde
Reviewed-By: @iarna
PR-URL: npm/npm#12485
  • Loading branch information
watilde authored and iarna committed Apr 28, 2016
1 parent 6cfbae4 commit a53feac
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/utils/usage.js
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a53feac

Please sign in to comment.