bdy 1.18.20-dev → 1.18.21-dev
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/distTs/package.json +1 -1
- package/distTs/src/main.js +20 -11
- package/package.json +1 -1
package/distTs/package.json
CHANGED
package/distTs/src/main.js
CHANGED
|
@@ -7,7 +7,7 @@ const output_1 = __importDefault(require("./output"));
|
|
|
7
7
|
const selectCommand = async (parentCommand) => {
|
|
8
8
|
let items = [];
|
|
9
9
|
const map = {};
|
|
10
|
-
parentCommand.commands.forEach((c) => {
|
|
10
|
+
parentCommand.commands.filter((c) => !c._hidden).forEach((c) => {
|
|
11
11
|
const name = c.name();
|
|
12
12
|
map[name] = c;
|
|
13
13
|
items.push({
|
|
@@ -22,7 +22,8 @@ const selectCommand = async (parentCommand) => {
|
|
|
22
22
|
value: 'help',
|
|
23
23
|
});
|
|
24
24
|
items = items.sort((a, b) => a.name.localeCompare(b.name));
|
|
25
|
-
|
|
25
|
+
output_1.default.clearPreviousLine();
|
|
26
|
+
const name = await output_1.default.inputMenuAdv(getFinalCommand(parentCommand, {}, []), items);
|
|
26
27
|
if (name === 'help') {
|
|
27
28
|
parentCommand.help();
|
|
28
29
|
output_1.default.exitNormal();
|
|
@@ -34,12 +35,17 @@ const selectCommand = async (parentCommand) => {
|
|
|
34
35
|
return cmd;
|
|
35
36
|
};
|
|
36
37
|
const setOptionValue = async (opt) => {
|
|
38
|
+
output_1.default.clearPreviousLine();
|
|
39
|
+
let name = opt.name();
|
|
40
|
+
const desc = opt.description;
|
|
41
|
+
if (desc)
|
|
42
|
+
name += ` (${desc})`;
|
|
37
43
|
if (opt.isBoolean()) {
|
|
38
|
-
const val = await output_1.default.inputMenu(
|
|
44
|
+
const val = await output_1.default.inputMenu(`--${name}`, ['true', 'false']);
|
|
39
45
|
return val === 0;
|
|
40
46
|
}
|
|
41
47
|
else {
|
|
42
|
-
return await output_1.default.inputString(
|
|
48
|
+
return await output_1.default.inputString(`--${name}:`, opt.defaultValue);
|
|
43
49
|
}
|
|
44
50
|
};
|
|
45
51
|
const nameToCamelCase = (name) => {
|
|
@@ -66,18 +72,19 @@ const selectOptions = async (cmd) => {
|
|
|
66
72
|
const name = opt.name();
|
|
67
73
|
map[name] = opt;
|
|
68
74
|
items.push({
|
|
69
|
-
name
|
|
75
|
+
name: `--${name}`,
|
|
70
76
|
description: opt.description,
|
|
71
77
|
value: name,
|
|
72
78
|
});
|
|
73
79
|
});
|
|
74
80
|
items = items.sort((a, b) => a.name.localeCompare(b.name));
|
|
75
81
|
items.unshift({
|
|
76
|
-
name: '
|
|
82
|
+
name: 'Skip options',
|
|
77
83
|
value: '',
|
|
78
84
|
});
|
|
79
85
|
while (true) {
|
|
80
|
-
|
|
86
|
+
output_1.default.clearPreviousLine();
|
|
87
|
+
const name = await output_1.default.inputMenuAdv(getFinalCommand(cmd, options, []), items);
|
|
81
88
|
if (map[name]) {
|
|
82
89
|
const opt = map[name];
|
|
83
90
|
const value = await setOptionValue(opt);
|
|
@@ -108,6 +115,7 @@ const selectArguments = async (cmd) => {
|
|
|
108
115
|
if (arg.description)
|
|
109
116
|
desc += ` - ${arg.description}`;
|
|
110
117
|
desc += ':';
|
|
118
|
+
output_1.default.clearPreviousLine();
|
|
111
119
|
const value = await output_1.default.inputString(`${desc[0].toUpperCase()}${desc.substring(1)}`, arg.defaultValue, arg.required);
|
|
112
120
|
if (arg.variadic) {
|
|
113
121
|
args.push(value.split(' '));
|
|
@@ -119,7 +127,7 @@ const selectArguments = async (cmd) => {
|
|
|
119
127
|
}
|
|
120
128
|
return args;
|
|
121
129
|
};
|
|
122
|
-
const
|
|
130
|
+
const getFinalCommand = (cmd, options, args) => {
|
|
123
131
|
let txt = '';
|
|
124
132
|
let c = cmd;
|
|
125
133
|
while (c !== null) {
|
|
@@ -152,8 +160,7 @@ const outputFinalCommand = (cmd, options, args) => {
|
|
|
152
160
|
txt += ` "${arg}"`;
|
|
153
161
|
}
|
|
154
162
|
});
|
|
155
|
-
|
|
156
|
-
output_1.default.normal(txt);
|
|
163
|
+
return txt;
|
|
157
164
|
};
|
|
158
165
|
const main = async (program) => {
|
|
159
166
|
if (!output_1.default.isTTY()) {
|
|
@@ -164,7 +171,9 @@ const main = async (program) => {
|
|
|
164
171
|
const options = await selectOptions(cmd);
|
|
165
172
|
const args = await selectArguments(cmd);
|
|
166
173
|
Object.entries(options).forEach(([k, v]) => cmd.setOptionValue(camelCaseToName(k), v));
|
|
167
|
-
|
|
174
|
+
output_1.default.clearPreviousLine();
|
|
175
|
+
output_1.default.cyan('❯ ', false);
|
|
176
|
+
output_1.default.normal(getFinalCommand(cmd, options, args));
|
|
168
177
|
await cmd._actionHandler([...args, options, cmd]);
|
|
169
178
|
};
|
|
170
179
|
exports.default = main;
|