1 | import { removeBrackets, camelcaseOptionName } from "./utils.ts";
|
2 | interface OptionConfig {
|
3 | default?: any;
|
4 | type?: any[];
|
5 | }
|
6 | export default class Option {
|
7 |
|
8 | name: string;
|
9 |
|
10 |
|
11 | names: string[];
|
12 | isBoolean?: boolean;
|
13 |
|
14 | required?: boolean;
|
15 | config: OptionConfig;
|
16 | negated: boolean;
|
17 |
|
18 | constructor(public rawName: string, public description: string, config?: OptionConfig) {
|
19 | this.config = Object.assign({}, config);
|
20 |
|
21 | rawName = rawName.replace(/\.\*/g, '');
|
22 | this.negated = false;
|
23 | this.names = removeBrackets(rawName).split(',').map((v: string) => {
|
24 | let name = v.trim().replace(/^-{1,2}/, '');
|
25 |
|
26 | if (name.startsWith('no-')) {
|
27 | this.negated = true;
|
28 | name = name.replace(/^no-/, '');
|
29 | }
|
30 |
|
31 | return camelcaseOptionName(name);
|
32 | }).sort((a, b) => a.length > b.length ? 1 : -1);
|
33 |
|
34 |
|
35 | this.name = this.names[this.names.length - 1];
|
36 |
|
37 | if (this.negated) {
|
38 | this.config.default = true;
|
39 | }
|
40 |
|
41 | if (rawName.includes('<')) {
|
42 | this.required = true;
|
43 | } else if (rawName.includes('[')) {
|
44 | this.required = false;
|
45 | } else {
|
46 |
|
47 | this.isBoolean = true;
|
48 | }
|
49 | }
|
50 |
|
51 | }
|
52 | export type { OptionConfig }; |
\ | No newline at end of file |