usage.js 576 B

123456789101112131415161718192021222324252627
  1. 'use strict'
  2. var aliases = require('../config/cmd-list').aliases
  3. module.exports = function usage (cmd, txt, opt) {
  4. var post = Object.keys(aliases).reduce(function (p, c) {
  5. var val = aliases[c]
  6. if (val !== cmd) return p
  7. return p.concat(c)
  8. }, [])
  9. if (opt || post.length > 0) txt += '\n\n'
  10. if (post.length === 1) {
  11. txt += 'alias: '
  12. txt += post.join(', ')
  13. } else if (post.length > 1) {
  14. txt += 'aliases: '
  15. txt += post.join(', ')
  16. }
  17. if (opt) {
  18. if (post.length > 0) txt += '\n'
  19. txt += 'common options: ' + opt
  20. }
  21. return txt
  22. }