bob-core 0.6.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CommandHelper.js +10 -1
- package/dist/Parser.d.ts +2 -1
- package/dist/Parser.js +24 -0
- package/package.json +1 -1
package/dist/CommandHelper.js
CHANGED
|
@@ -13,6 +13,7 @@ class CommandHelper {
|
|
|
13
13
|
{
|
|
14
14
|
name: 'help',
|
|
15
15
|
optional: true,
|
|
16
|
+
type: 'boolean',
|
|
16
17
|
help: (0, chalk_1.default) `Display help for the given command. When no command is given display help for the {green list} command`,
|
|
17
18
|
alias: ['h']
|
|
18
19
|
}
|
|
@@ -45,7 +46,15 @@ class CommandHelper {
|
|
|
45
46
|
log((0, chalk_1.default) `\n{yellow Options}:`);
|
|
46
47
|
for (const signature of availableOptions) {
|
|
47
48
|
const spaces = (0, string_1.generateSpace)(maxLength - signature.optionWithAlias.length);
|
|
48
|
-
|
|
49
|
+
let message = (0, chalk_1.default) `{green ${signature.optionWithAlias}} ${spaces} ${signature.help ?? '\b'}`;
|
|
50
|
+
if (signature.type) {
|
|
51
|
+
message += (0, chalk_1.default) ` {white (${signature.type})}`;
|
|
52
|
+
}
|
|
53
|
+
if (signature.defaultValue !== undefined && signature.optional) {
|
|
54
|
+
const value = signature.type === 'array' ? JSON.stringify(signature.defaultValue) : signature.defaultValue;
|
|
55
|
+
message += (0, chalk_1.default) ` {yellow [default: ${value}]}`;
|
|
56
|
+
}
|
|
57
|
+
log(message);
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
60
|
if (this.commandsExamples.length > 0) {
|
package/dist/Parser.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export type ArgSignature = {
|
|
2
2
|
name: string;
|
|
3
|
+
type: string;
|
|
3
4
|
optional: boolean;
|
|
4
5
|
alias?: string[];
|
|
5
6
|
help?: string;
|
|
6
|
-
defaultValue?: string | boolean | null;
|
|
7
|
+
defaultValue?: string | boolean | Array<any> | null;
|
|
7
8
|
isOption?: boolean;
|
|
8
9
|
};
|
|
9
10
|
export declare class Parser {
|
package/dist/Parser.js
CHANGED
|
@@ -15,6 +15,22 @@ class Parser {
|
|
|
15
15
|
argumentsSignature = {};
|
|
16
16
|
optionsSignature = {};
|
|
17
17
|
option(name) {
|
|
18
|
+
if (!this.optionsSignature[name]) {
|
|
19
|
+
throw new Error(`Option ${name} not found`);
|
|
20
|
+
}
|
|
21
|
+
const signature = this.optionsSignature[name];
|
|
22
|
+
if (signature.type === 'boolean') {
|
|
23
|
+
if (this.options[name] === 'true' || this.options[name] === '1') {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
else if (this.options[name] === 'false' || this.options[name] === '0') {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return Boolean(this.options[name]);
|
|
30
|
+
}
|
|
31
|
+
if (signature.type === 'array') {
|
|
32
|
+
return Array.isArray(this.options[name]) ? this.options[name] : [this.options[name]];
|
|
33
|
+
}
|
|
18
34
|
return this.options[name];
|
|
19
35
|
}
|
|
20
36
|
argument(name) {
|
|
@@ -65,6 +81,7 @@ class Parser {
|
|
|
65
81
|
const arg = {
|
|
66
82
|
name: cleanedArgs,
|
|
67
83
|
optional: isOptional,
|
|
84
|
+
type: 'string',
|
|
68
85
|
help: undefined,
|
|
69
86
|
defaultValue: null,
|
|
70
87
|
isOption: false
|
|
@@ -84,14 +101,17 @@ class Parser {
|
|
|
84
101
|
}
|
|
85
102
|
else if (arg.defaultValue === 'true') {
|
|
86
103
|
arg.defaultValue = true;
|
|
104
|
+
arg.type = 'boolean';
|
|
87
105
|
}
|
|
88
106
|
else if (arg.defaultValue === 'false') {
|
|
89
107
|
arg.defaultValue = false;
|
|
108
|
+
arg.type = 'boolean';
|
|
90
109
|
}
|
|
91
110
|
}
|
|
92
111
|
else {
|
|
93
112
|
if (arg.name.startsWith('--')) {
|
|
94
113
|
arg.defaultValue = false;
|
|
114
|
+
arg.type = 'boolean';
|
|
95
115
|
}
|
|
96
116
|
}
|
|
97
117
|
if (arg.name.includes('|')) {
|
|
@@ -103,6 +123,10 @@ class Parser {
|
|
|
103
123
|
arg.isOption = true;
|
|
104
124
|
arg.name = arg.name.slice(2);
|
|
105
125
|
}
|
|
126
|
+
if (arg.defaultValue === '*') {
|
|
127
|
+
arg.defaultValue = [];
|
|
128
|
+
arg.type = 'array';
|
|
129
|
+
}
|
|
106
130
|
if (this.helperDefinitions[arg.name]) {
|
|
107
131
|
arg.help = this.helperDefinitions[arg.name];
|
|
108
132
|
}
|