GT2/GT2-Android/node_modules/jest-util/build/validate_cli_options.js

61 lines
4.6 KiB
JavaScript
Raw Normal View History

'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.default =
validateCLIOptions;var _chalk;function _load_chalk() {return _chalk = _interopRequireDefault(require('chalk'));}var _jestValidate;function _load_jestValidate() {return _jestValidate = require('jest-validate');}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}const BULLET = (_chalk || _load_chalk()).default.bold('\u25cf'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/const createCLIValidationError = (unrecognizedOptions, allowedOptions) => {let title = `${BULLET} Unrecognized CLI Parameter`;let message;const comment = ` ${(_chalk || _load_chalk()).default.bold('CLI Options Documentation')}:\n` + ` https://facebook.github.io/jest/docs/en/cli.html\n`;if (unrecognizedOptions.length === 1) {const unrecognized = unrecognizedOptions[0];const didYouMeanMessage = (0, (_jestValidate || _load_jestValidate()).createDidYouMeanMessage)(unrecognized, Array.from(allowedOptions));message = ` Unrecognized option ${(_chalk || _load_chalk()).default.bold((0, (_jestValidate || _load_jestValidate()).format)(unrecognized))}.` + (didYouMeanMessage ? ` ${didYouMeanMessage}` : '');} else {title += 's';message = ` Following options were not recognized:\n` + ` ${(_chalk || _load_chalk()).default.bold((0, (_jestValidate || _load_jestValidate()).format)(unrecognizedOptions))}`;}return new (_jestValidate || _load_jestValidate()).ValidationError(title, message, comment);};function validateCLIOptions(argv, options) {const yargsSpecialOptions = ['$0', '_', 'help', 'h'];const allowedOptions = Object.keys(options).reduce((acc, option) => acc.add(option).add(options[option].alias || option), new Set(yargsSpecialOptions));const unrecognizedOptions = Object.keys(argv).filter(arg => !allowedOptions.has(arg));
if (unrecognizedOptions.length) {
throw createCLIValidationError(unrecognizedOptions, allowedOptions);
}
return true;
}