easc 0.0.23 → 0.0.25
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/package.json +1 -1
- package/src/utils/cli.ts +29 -4
package/package.json
CHANGED
package/src/utils/cli.ts
CHANGED
|
@@ -2,6 +2,14 @@ import yargs, { type Argv, type CommandModule, type Options } from "yargs";
|
|
|
2
2
|
import { select } from "@inquirer/prompts";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
|
|
5
|
+
// Custom error to signal going back to menu
|
|
6
|
+
class BackToMenuError extends Error {
|
|
7
|
+
constructor() {
|
|
8
|
+
super("Back to menu");
|
|
9
|
+
this.name = "BackToMenuError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
interface CommandInfo {
|
|
6
14
|
command: string;
|
|
7
15
|
describe: string;
|
|
@@ -137,8 +145,16 @@ class InteractiveCLI {
|
|
|
137
145
|
return y;
|
|
138
146
|
},
|
|
139
147
|
handler: async (argv: any) => {
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
try {
|
|
149
|
+
await this._promptForMissingArgs(argv, cmd.options);
|
|
150
|
+
return cmd.handler(argv);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (error instanceof BackToMenuError) {
|
|
153
|
+
this.args = [];
|
|
154
|
+
return this.parse();
|
|
155
|
+
}
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
142
158
|
},
|
|
143
159
|
});
|
|
144
160
|
}
|
|
@@ -173,10 +189,19 @@ class InteractiveCLI {
|
|
|
173
189
|
if (opt.default !== undefined) continue;
|
|
174
190
|
if (!opt.choices || !Array.isArray(opt.choices)) continue;
|
|
175
191
|
|
|
176
|
-
|
|
192
|
+
const selected = await select({
|
|
177
193
|
message: `Select ${key.replace(/-/g, " ")}:`,
|
|
178
|
-
choices:
|
|
194
|
+
choices: [
|
|
195
|
+
...opt.choices.map((c: string) => ({ name: c, value: c })),
|
|
196
|
+
{ name: "← Back", value: "__back__" },
|
|
197
|
+
],
|
|
179
198
|
});
|
|
199
|
+
|
|
200
|
+
if (selected === "__back__") {
|
|
201
|
+
throw new BackToMenuError();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
argv[key] = selected;
|
|
180
205
|
argv[camelKey] = argv[key];
|
|
181
206
|
}
|
|
182
207
|
}
|