MCPcopy Create free account
hub / github.com/hashintel/hash / promptHidden

Function promptHidden

apps/hash-api/src/setup-admin.ts:36–82  ·  view source on GitHub ↗
(label: string)

Source from the content-addressed store, hash-verified

34 * (piped/non-interactive input).
35 */
36const promptHidden = (label: string): Promise<string> => {
37 const { stdin, stdout } = process;
38
39 if (!stdin.isTTY) {
40 return promptVisible(label);
41 }
42
43 return new Promise((resolve) => {
44 stdout.write(`${label}: `);
45 stdin.setRawMode(true);
46 stdin.resume();
47 stdin.setEncoding("utf8");
48
49 let buffer = "";
50 const onData = (char: string) => {
51 const code = char.charCodeAt(0);
52 // CR / LF / Ctrl+D — finish
53 if (code === 13 || code === 10 || code === 4) {
54 stdin.setRawMode(false);
55 stdin.pause();
56 stdin.off("data", onData);
57 stdout.write("\n");
58 resolve(buffer);
59 return;
60 }
61 // Ctrl+C — abort
62 if (code === 3) {
63 stdin.setRawMode(false);
64 stdin.pause();
65 stdout.write("\n");
66 process.exit(130);
67 }
68 // DEL / BS — erase last char
69 if (code === 127 || code === 8) {
70 if (buffer.length > 0) {
71 buffer = buffer.slice(0, -1);
72 stdout.write("\b \b");
73 }
74 return;
75 }
76 buffer += char;
77 stdout.write("*");
78 };
79
80 stdin.on("data", onData);
81 });
82};
83
84const [, , emailArg, passwordArg] = process.argv;
85

Callers 1

setup-admin.tsFile · 0.85

Calls 4

promptVisibleFunction · 0.85
resumeMethod · 0.80
writeMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected