diff options
Diffstat (limited to 'lib/utils')
-rw-r--r-- | lib/utils/cmd-list.js | 158 | ||||
-rw-r--r-- | lib/utils/deref-command.js | 31 | ||||
-rw-r--r-- | lib/utils/npm-usage.js | 2 |
3 files changed, 81 insertions, 110 deletions
diff --git a/lib/utils/cmd-list.js b/lib/utils/cmd-list.js index 1469ebdd6..c1d20186a 100644 --- a/lib/utils/cmd-list.js +++ b/lib/utils/cmd-list.js @@ -1,5 +1,23 @@ -// short names for common things -const shorthands = { +const abbrev = require('abbrev') + +// plumbing should not have any aliases +const aliases = { + + // aliases + login: 'adduser', + author: 'owner', + home: 'docs', + issues: 'bugs', + info: 'view', + show: 'view', + find: 'search', + add: 'install', + unlink: 'uninstall', + remove: 'uninstall', + rm: 'uninstall', + r: 'uninstall', + + // short names for common things un: 'uninstall', rb: 'rebuild', list: 'ls', @@ -21,12 +39,11 @@ const shorthands = { 'clean-install-test': 'cit', x: 'exec', why: 'explain', -} - -const affordances = { la: 'll', verison: 'version', ic: 'ci', + + // typos innit: 'init', // manually abbrev so that install-test doesn't make insta stop working in: 'install', @@ -44,105 +61,90 @@ const affordances = { 'dist-tags': 'dist-tag', upgrade: 'update', udpate: 'update', - login: 'adduser', - 'add-user': 'adduser', - author: 'owner', - home: 'docs', - issues: 'bugs', - info: 'view', - show: 'view', - find: 'search', - add: 'install', - unlink: 'uninstall', - remove: 'uninstall', - rm: 'uninstall', - r: 'uninstall', rum: 'run-script', sit: 'cit', urn: 'run-script', ogr: 'org', + 'add-user': 'adduser', } // these are filenames in . +// Keep these sorted so that lib/utils/npm-usage.js outputs in order const cmdList = [ - 'ci', - 'install-ci-test', - 'install', - 'install-test', - 'uninstall', + 'access', + 'adduser', + 'audit', + 'bin', + 'bugs', 'cache', + 'ci', + 'completion', 'config', - 'set', - 'get', - 'update', - 'outdated', - 'prune', - 'pack', - 'find-dupes', 'dedupe', + 'deprecate', + 'diff', + 'dist-tag', + 'docs', + 'doctor', + 'edit', + 'exec', + 'explain', + 'explore', + 'find-dupes', + 'fund', + 'get', + 'help', 'hook', - - 'rebuild', + 'init', + 'install', + 'install-ci-test', + 'install-test', 'link', - - 'publish', - 'star', - 'stars', - 'unstar', - 'adduser', + 'll', 'login', // This is an alias for `adduser` but it can be confusing 'logout', - 'unpublish', - 'owner', - 'access', - 'team', - 'deprecate', - 'shrinkwrap', - 'token', - 'profile', - 'audit', - 'fund', - 'org', - - 'help', 'ls', - 'll', - 'search', - 'view', - 'init', - 'version', - 'edit', - 'explore', - 'docs', - 'repo', - 'bugs', - 'root', - 'prefix', - 'bin', - 'whoami', - 'diff', - 'dist-tag', + 'org', + 'outdated', + 'owner', + 'pack', 'ping', 'pkg', - - 'test', - 'stop', - 'start', + 'prefix', + 'profile', + 'prune', + 'publish', + 'rebuild', + 'repo', 'restart', + 'root', 'run-script', + 'search', + 'set', 'set-script', - 'completion', - 'doctor', - 'exec', - 'explain', + 'shrinkwrap', + 'star', + 'stars', + 'start', + 'stop', + 'team', + 'test', + 'token', + 'uninstall', + 'unpublish', + 'unstar', + 'update', + 'version', + 'view', + 'whoami', ] const plumbing = ['birthday', 'help-search'] +const abbrevs = abbrev(cmdList.concat(Object.keys(aliases))) module.exports = { - aliases: Object.assign({}, shorthands, affordances), - shorthands, - affordances, + abbrevs, + aliases, cmdList, plumbing, } diff --git a/lib/utils/deref-command.js b/lib/utils/deref-command.js deleted file mode 100644 index 0a3c8c90b..000000000 --- a/lib/utils/deref-command.js +++ /dev/null @@ -1,31 +0,0 @@ -// de-reference abbreviations and shorthands into canonical command name - -const { aliases, cmdList, plumbing } = require('./cmd-list.js') -const aliasNames = Object.keys(aliases) -const fullList = cmdList.concat(aliasNames).filter(c => !plumbing.includes(c)) -const abbrev = require('abbrev') -const abbrevs = abbrev(fullList) - -module.exports = c => { - if (!c || typeof c !== 'string') { - return '' - } - - if (c.match(/[A-Z]/)) { - c = c.replace(/([A-Z])/g, m => '-' + m.toLowerCase()) - } - - if (plumbing.indexOf(c) !== -1) { - return c - } - - // first deref the abbrev, if there is one - // then resolve any aliases - // so `npm install-cl` will resolve to `install-clean` then to `ci` - let a = abbrevs[c] - while (aliases[a]) { - a = aliases[a] - } - - return a || '' -} diff --git a/lib/utils/npm-usage.js b/lib/utils/npm-usage.js index b0c98b2ae..8d31f0155 100644 --- a/lib/utils/npm-usage.js +++ b/lib/utils/npm-usage.js @@ -45,7 +45,7 @@ const wrap = (arr) => { : Math.min(60, Math.max(process.stdout.columns - 16, 24)) let l = 0 - for (const c of arr.sort((a, b) => a < b ? -1 : 1)) { + for (const c of arr) { if (out[l].length + c.length + 2 < line) { out[l] += ', ' + c } else { |