index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const flatten = require('./flatten.js')
  2. const definitions = require('./definitions.js')
  3. const describeAll = require('./describe-all.js')
  4. // aliases where they get expanded into a completely different thing
  5. // these are NOT supported in the environment or npmrc files, only
  6. // expanded on the CLI.
  7. // TODO: when we switch off of nopt, use an arg parser that supports
  8. // more reasonable aliasing and short opts right in the definitions set.
  9. const shorthands = {
  10. 'enjoy-by': ['--before'],
  11. d: ['--loglevel', 'info'],
  12. dd: ['--loglevel', 'verbose'],
  13. ddd: ['--loglevel', 'silly'],
  14. quiet: ['--loglevel', 'warn'],
  15. q: ['--loglevel', 'warn'],
  16. s: ['--loglevel', 'silent'],
  17. silent: ['--loglevel', 'silent'],
  18. verbose: ['--loglevel', 'verbose'],
  19. desc: ['--description'],
  20. help: ['--usage'],
  21. local: ['--no-global'],
  22. n: ['--no-yes'],
  23. no: ['--no-yes'],
  24. porcelain: ['--parseable'],
  25. readonly: ['--read-only'],
  26. reg: ['--registry'],
  27. }
  28. for (const [key, {short}] of Object.entries(definitions)) {
  29. if (!short)
  30. continue
  31. // can be either an array or string
  32. for (const s of [].concat(short))
  33. shorthands[s] = [`--${key}`]
  34. }
  35. module.exports = {
  36. get defaults () {
  37. // NB: 'default' is a reserved word
  38. return Object.entries(definitions).map(([key, { default: def }]) => {
  39. return [key, def]
  40. }).reduce((defaults, [key, def]) => {
  41. defaults[key] = def
  42. return defaults
  43. }, {})
  44. },
  45. definitions,
  46. flatten,
  47. shorthands,
  48. describeAll,
  49. }