Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validateCLIOptions.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = validateCLIOptions;
  6. exports.DOCUMENTATION_NOTE = void 0;
  7. function _camelcase() {
  8. const data = _interopRequireDefault(require('camelcase'));
  9. _camelcase = function () {
  10. return data;
  11. };
  12. return data;
  13. }
  14. function _chalk() {
  15. const data = _interopRequireDefault(require('chalk'));
  16. _chalk = function () {
  17. return data;
  18. };
  19. return data;
  20. }
  21. var _defaultConfig = _interopRequireDefault(require('./defaultConfig'));
  22. var _deprecated = require('./deprecated');
  23. var _utils = require('./utils');
  24. function _interopRequireDefault(obj) {
  25. return obj && obj.__esModule ? obj : {default: obj};
  26. }
  27. /**
  28. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  29. *
  30. * This source code is licensed under the MIT license found in the
  31. * LICENSE file in the root directory of this source tree.
  32. */
  33. const BULLET = _chalk().default.bold('\u25cf');
  34. const DOCUMENTATION_NOTE = ` ${_chalk().default.bold(
  35. 'CLI Options Documentation:'
  36. )}
  37. https://jestjs.io/docs/cli
  38. `;
  39. exports.DOCUMENTATION_NOTE = DOCUMENTATION_NOTE;
  40. const createCLIValidationError = (unrecognizedOptions, allowedOptions) => {
  41. let title = `${BULLET} Unrecognized CLI Parameter`;
  42. let message;
  43. const comment =
  44. ` ${_chalk().default.bold('CLI Options Documentation')}:\n` +
  45. ` https://jestjs.io/docs/cli\n`;
  46. if (unrecognizedOptions.length === 1) {
  47. const unrecognized = unrecognizedOptions[0];
  48. const didYouMeanMessage =
  49. unrecognized.length > 1
  50. ? (0, _utils.createDidYouMeanMessage)(
  51. unrecognized,
  52. Array.from(allowedOptions)
  53. )
  54. : '';
  55. message =
  56. ` Unrecognized option ${_chalk().default.bold(
  57. (0, _utils.format)(unrecognized)
  58. )}.` + (didYouMeanMessage ? ` ${didYouMeanMessage}` : '');
  59. } else {
  60. title += 's';
  61. message =
  62. ` Following options were not recognized:\n` +
  63. ` ${_chalk().default.bold((0, _utils.format)(unrecognizedOptions))}`;
  64. }
  65. return new _utils.ValidationError(title, message, comment);
  66. };
  67. const logDeprecatedOptions = (deprecatedOptions, deprecationEntries, argv) => {
  68. deprecatedOptions.forEach(opt => {
  69. (0, _deprecated.deprecationWarning)(argv, opt, deprecationEntries, {
  70. ..._defaultConfig.default,
  71. comment: DOCUMENTATION_NOTE
  72. });
  73. });
  74. };
  75. function validateCLIOptions(argv, options, rawArgv = []) {
  76. const yargsSpecialOptions = ['$0', '_', 'help', 'h'];
  77. const deprecationEntries = options.deprecationEntries || {};
  78. const allowedOptions = Object.keys(options).reduce(
  79. (acc, option) => acc.add(option).add(options[option].alias || option),
  80. new Set(yargsSpecialOptions)
  81. );
  82. const unrecognizedOptions = Object.keys(argv).filter(
  83. arg =>
  84. !allowedOptions.has(
  85. (0, _camelcase().default)(arg, {
  86. locale: 'en-US'
  87. })
  88. ) &&
  89. !allowedOptions.has(arg) &&
  90. (!rawArgv.length || rawArgv.includes(arg)),
  91. []
  92. );
  93. if (unrecognizedOptions.length) {
  94. throw createCLIValidationError(unrecognizedOptions, allowedOptions);
  95. }
  96. const CLIDeprecations = Object.keys(deprecationEntries).reduce(
  97. (acc, entry) => {
  98. if (options[entry]) {
  99. acc[entry] = deprecationEntries[entry];
  100. const alias = options[entry].alias;
  101. if (alias) {
  102. acc[alias] = deprecationEntries[entry];
  103. }
  104. }
  105. return acc;
  106. },
  107. {}
  108. );
  109. const deprecations = new Set(Object.keys(CLIDeprecations));
  110. const deprecatedOptions = Object.keys(argv).filter(
  111. arg => deprecations.has(arg) && argv[arg] != null
  112. );
  113. if (deprecatedOptions.length) {
  114. logDeprecatedOptions(deprecatedOptions, CLIDeprecations, argv);
  115. }
  116. return true;
  117. }