1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.defaultFlags = exports.string = exports.option = exports.integer = exports.boolean = exports.build = void 0;
|
5 | function build(defaults) {
|
6 | return (options = {}) => {
|
7 | return Object.assign(Object.assign(Object.assign({ parse: (i, _) => i }, defaults), options), { input: [], multiple: Boolean(options.multiple), type: 'option' });
|
8 | };
|
9 | }
|
10 | exports.build = build;
|
11 | function boolean(options = {}) {
|
12 | return Object.assign(Object.assign({ parse: (b, _) => b }, options), { allowNo: Boolean(options.allowNo), type: 'boolean' });
|
13 | }
|
14 | exports.boolean = boolean;
|
15 | exports.integer = build({
|
16 | parse: input => {
|
17 | if (!/^-?\d+$/.test(input))
|
18 | throw new Error(`Expected an integer but received: ${input}`);
|
19 | return parseInt(input, 10);
|
20 | },
|
21 | });
|
22 | function option(options) {
|
23 | return build(options)();
|
24 | }
|
25 | exports.option = option;
|
26 | const stringFlag = build({});
|
27 | exports.string = stringFlag;
|
28 | exports.defaultFlags = {
|
29 | color: boolean({ allowNo: true }),
|
30 | };
|