11cb0ef41Sopenharmony_ciconst abbrev = require('abbrev')
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// These correspond to filenames in lib/commands
41cb0ef41Sopenharmony_ci// Please keep this list sorted alphabetically
51cb0ef41Sopenharmony_ciconst commands = [
61cb0ef41Sopenharmony_ci  'access',
71cb0ef41Sopenharmony_ci  'adduser',
81cb0ef41Sopenharmony_ci  'audit',
91cb0ef41Sopenharmony_ci  'bugs',
101cb0ef41Sopenharmony_ci  'cache',
111cb0ef41Sopenharmony_ci  'ci',
121cb0ef41Sopenharmony_ci  'completion',
131cb0ef41Sopenharmony_ci  'config',
141cb0ef41Sopenharmony_ci  'dedupe',
151cb0ef41Sopenharmony_ci  'deprecate',
161cb0ef41Sopenharmony_ci  'diff',
171cb0ef41Sopenharmony_ci  'dist-tag',
181cb0ef41Sopenharmony_ci  'docs',
191cb0ef41Sopenharmony_ci  'doctor',
201cb0ef41Sopenharmony_ci  'edit',
211cb0ef41Sopenharmony_ci  'exec',
221cb0ef41Sopenharmony_ci  'explain',
231cb0ef41Sopenharmony_ci  'explore',
241cb0ef41Sopenharmony_ci  'find-dupes',
251cb0ef41Sopenharmony_ci  'fund',
261cb0ef41Sopenharmony_ci  'get',
271cb0ef41Sopenharmony_ci  'help',
281cb0ef41Sopenharmony_ci  'help-search',
291cb0ef41Sopenharmony_ci  'hook',
301cb0ef41Sopenharmony_ci  'init',
311cb0ef41Sopenharmony_ci  'install',
321cb0ef41Sopenharmony_ci  'install-ci-test',
331cb0ef41Sopenharmony_ci  'install-test',
341cb0ef41Sopenharmony_ci  'link',
351cb0ef41Sopenharmony_ci  'll',
361cb0ef41Sopenharmony_ci  'login',
371cb0ef41Sopenharmony_ci  'logout',
381cb0ef41Sopenharmony_ci  'ls',
391cb0ef41Sopenharmony_ci  'org',
401cb0ef41Sopenharmony_ci  'outdated',
411cb0ef41Sopenharmony_ci  'owner',
421cb0ef41Sopenharmony_ci  'pack',
431cb0ef41Sopenharmony_ci  'ping',
441cb0ef41Sopenharmony_ci  'pkg',
451cb0ef41Sopenharmony_ci  'prefix',
461cb0ef41Sopenharmony_ci  'profile',
471cb0ef41Sopenharmony_ci  'prune',
481cb0ef41Sopenharmony_ci  'publish',
491cb0ef41Sopenharmony_ci  'query',
501cb0ef41Sopenharmony_ci  'rebuild',
511cb0ef41Sopenharmony_ci  'repo',
521cb0ef41Sopenharmony_ci  'restart',
531cb0ef41Sopenharmony_ci  'root',
541cb0ef41Sopenharmony_ci  'run-script',
551cb0ef41Sopenharmony_ci  'sbom',
561cb0ef41Sopenharmony_ci  'search',
571cb0ef41Sopenharmony_ci  'set',
581cb0ef41Sopenharmony_ci  'shrinkwrap',
591cb0ef41Sopenharmony_ci  'star',
601cb0ef41Sopenharmony_ci  'stars',
611cb0ef41Sopenharmony_ci  'start',
621cb0ef41Sopenharmony_ci  'stop',
631cb0ef41Sopenharmony_ci  'team',
641cb0ef41Sopenharmony_ci  'test',
651cb0ef41Sopenharmony_ci  'token',
661cb0ef41Sopenharmony_ci  'uninstall',
671cb0ef41Sopenharmony_ci  'unpublish',
681cb0ef41Sopenharmony_ci  'unstar',
691cb0ef41Sopenharmony_ci  'update',
701cb0ef41Sopenharmony_ci  'version',
711cb0ef41Sopenharmony_ci  'view',
721cb0ef41Sopenharmony_ci  'whoami',
731cb0ef41Sopenharmony_ci]
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci// These must resolve to an entry in commands
761cb0ef41Sopenharmony_ciconst aliases = {
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci  // aliases
791cb0ef41Sopenharmony_ci  author: 'owner',
801cb0ef41Sopenharmony_ci  home: 'docs',
811cb0ef41Sopenharmony_ci  issues: 'bugs',
821cb0ef41Sopenharmony_ci  info: 'view',
831cb0ef41Sopenharmony_ci  show: 'view',
841cb0ef41Sopenharmony_ci  find: 'search',
851cb0ef41Sopenharmony_ci  add: 'install',
861cb0ef41Sopenharmony_ci  unlink: 'uninstall',
871cb0ef41Sopenharmony_ci  remove: 'uninstall',
881cb0ef41Sopenharmony_ci  rm: 'uninstall',
891cb0ef41Sopenharmony_ci  r: 'uninstall',
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci  // short names for common things
921cb0ef41Sopenharmony_ci  un: 'uninstall',
931cb0ef41Sopenharmony_ci  rb: 'rebuild',
941cb0ef41Sopenharmony_ci  list: 'ls',
951cb0ef41Sopenharmony_ci  ln: 'link',
961cb0ef41Sopenharmony_ci  create: 'init',
971cb0ef41Sopenharmony_ci  i: 'install',
981cb0ef41Sopenharmony_ci  it: 'install-test',
991cb0ef41Sopenharmony_ci  cit: 'install-ci-test',
1001cb0ef41Sopenharmony_ci  up: 'update',
1011cb0ef41Sopenharmony_ci  c: 'config',
1021cb0ef41Sopenharmony_ci  s: 'search',
1031cb0ef41Sopenharmony_ci  se: 'search',
1041cb0ef41Sopenharmony_ci  tst: 'test',
1051cb0ef41Sopenharmony_ci  t: 'test',
1061cb0ef41Sopenharmony_ci  ddp: 'dedupe',
1071cb0ef41Sopenharmony_ci  v: 'view',
1081cb0ef41Sopenharmony_ci  run: 'run-script',
1091cb0ef41Sopenharmony_ci  'clean-install': 'ci',
1101cb0ef41Sopenharmony_ci  'clean-install-test': 'install-ci-test',
1111cb0ef41Sopenharmony_ci  x: 'exec',
1121cb0ef41Sopenharmony_ci  why: 'explain',
1131cb0ef41Sopenharmony_ci  la: 'll',
1141cb0ef41Sopenharmony_ci  verison: 'version',
1151cb0ef41Sopenharmony_ci  ic: 'ci',
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci  // typos
1181cb0ef41Sopenharmony_ci  innit: 'init',
1191cb0ef41Sopenharmony_ci  // manually abbrev so that install-test doesn't make insta stop working
1201cb0ef41Sopenharmony_ci  in: 'install',
1211cb0ef41Sopenharmony_ci  ins: 'install',
1221cb0ef41Sopenharmony_ci  inst: 'install',
1231cb0ef41Sopenharmony_ci  insta: 'install',
1241cb0ef41Sopenharmony_ci  instal: 'install',
1251cb0ef41Sopenharmony_ci  isnt: 'install',
1261cb0ef41Sopenharmony_ci  isnta: 'install',
1271cb0ef41Sopenharmony_ci  isntal: 'install',
1281cb0ef41Sopenharmony_ci  isntall: 'install',
1291cb0ef41Sopenharmony_ci  'install-clean': 'ci',
1301cb0ef41Sopenharmony_ci  'isntall-clean': 'ci',
1311cb0ef41Sopenharmony_ci  hlep: 'help',
1321cb0ef41Sopenharmony_ci  'dist-tags': 'dist-tag',
1331cb0ef41Sopenharmony_ci  upgrade: 'update',
1341cb0ef41Sopenharmony_ci  udpate: 'update',
1351cb0ef41Sopenharmony_ci  rum: 'run-script',
1361cb0ef41Sopenharmony_ci  sit: 'install-ci-test',
1371cb0ef41Sopenharmony_ci  urn: 'run-script',
1381cb0ef41Sopenharmony_ci  ogr: 'org',
1391cb0ef41Sopenharmony_ci  'add-user': 'adduser',
1401cb0ef41Sopenharmony_ci}
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ciconst deref = (c) => {
1431cb0ef41Sopenharmony_ci  if (!c) {
1441cb0ef41Sopenharmony_ci    return
1451cb0ef41Sopenharmony_ci  }
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ci  // Translate camelCase to snake-case (i.e. installTest to install-test)
1481cb0ef41Sopenharmony_ci  if (c.match(/[A-Z]/)) {
1491cb0ef41Sopenharmony_ci    c = c.replace(/([A-Z])/g, m => '-' + m.toLowerCase())
1501cb0ef41Sopenharmony_ci  }
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ci  // if they asked for something exactly we are done
1531cb0ef41Sopenharmony_ci  if (commands.includes(c)) {
1541cb0ef41Sopenharmony_ci    return c
1551cb0ef41Sopenharmony_ci  }
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ci  // if they asked for a direct alias
1581cb0ef41Sopenharmony_ci  if (aliases[c]) {
1591cb0ef41Sopenharmony_ci    return aliases[c]
1601cb0ef41Sopenharmony_ci  }
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci  const abbrevs = abbrev(commands.concat(Object.keys(aliases)))
1631cb0ef41Sopenharmony_ci
1641cb0ef41Sopenharmony_ci  // first deref the abbrev, if there is one
1651cb0ef41Sopenharmony_ci  // then resolve any aliases
1661cb0ef41Sopenharmony_ci  // so `npm install-cl` will resolve to `install-clean` then to `ci`
1671cb0ef41Sopenharmony_ci  let a = abbrevs[c]
1681cb0ef41Sopenharmony_ci  while (aliases[a]) {
1691cb0ef41Sopenharmony_ci    a = aliases[a]
1701cb0ef41Sopenharmony_ci  }
1711cb0ef41Sopenharmony_ci  return a
1721cb0ef41Sopenharmony_ci}
1731cb0ef41Sopenharmony_ci
1741cb0ef41Sopenharmony_cimodule.exports = {
1751cb0ef41Sopenharmony_ci  aliases,
1761cb0ef41Sopenharmony_ci  commands,
1771cb0ef41Sopenharmony_ci  deref,
1781cb0ef41Sopenharmony_ci}
179