forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-utilities.mjs
More file actions
46 lines (46 loc) · 1.31 KB
/
Copy pathcli-utilities.mjs
File metadata and controls
46 lines (46 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { t as src_default } from "./src.mjs";
import { cancel, confirm, groupMultiselect, isCancel, note, select, text } from "@clack/prompts";
//#region src/utils/cli-utilities.ts
async function cancelable(task) {
const result = await task();
if (isCancel(result)) {
cancel("Canceled... 👋 ");
process.exit(0);
}
return result;
}
function importantWarning(message) {
note(message.trim(), src_default.yellow("IMPORTANT"), { format: src_default.white });
}
async function askMultiselect(message, values, options) {
return cancelable(async () => groupMultiselect({
selectableGroups: true,
required: false,
...options,
message,
options: values
}));
}
async function askQuestion(message, { placeholder, notEmpty } = {}) {
return cancelable(() => text({
message,
placeholder,
validate: (input = "") => notEmpty && input.length === 0 ? `Can't be empty.` : void 0
}));
}
async function askConfirm(message, initialValue = true) {
return cancelable(() => confirm({
message,
initialValue
}));
}
async function askList(message, choices) {
return cancelable(() => {
return select({
message,
options: choices.map((choice) => typeof choice === "string" ? { value: choice } : choice)
});
});
}
//#endregion
export { importantWarning as a, askQuestion as i, askList as n, askMultiselect as r, askConfirm as t };