UNPKG

1.17 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = assertRequiredOptions;
7
8function _commander() {
9 const data = require("commander");
10
11 _commander = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _lodash() {
19 const data = require("lodash");
20
21 _lodash = function () {
22 return data;
23 };
24
25 return data;
26}
27
28/**
29 * Copyright (c) Facebook, Inc. and its affiliates.
30 *
31 * This source code is licensed under the MIT license found in the
32 * LICENSE file in the root directory of this source tree.
33 *
34 * @format
35 */
36// Commander.js has a 2 years old open issue to support <...> syntax
37// for options. Until that gets merged, we run the checks manually
38// https://github.com/tj/commander.js/issues/230
39function assertRequiredOptions(options, passedOptions) {
40 options.forEach(opt => {
41 const option = new (_commander().Option)(opt.name);
42
43 if (!option.required) {
44 return;
45 }
46
47 const name = (0, _lodash().camelCase)(option.long);
48
49 if (!passedOptions[name]) {
50 // Provide commander.js like error message
51 throw new Error(`Option "${option.long}" is missing`);
52 }
53 });
54}
\No newline at end of file