-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-cli-example.run
More file actions
executable file
·45 lines (37 loc) · 919 Bytes
/
Copy pathnode-cli-example.run
File metadata and controls
executable file
·45 lines (37 loc) · 919 Bytes
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
#!/usr/bin/env node
const readline = require("readline");
// instantiate a readline
const cli = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: "\n> ",
});
// prompts the user and waits for input
cli.prompt();
// listen for user input
cli.on("line", (line) => {
const input = line.trim();
switch (input) {
case "env": {
for (const variable in process.env) {
console.log(`${variable}: ${process.env[variable]}`);
}
break;
}
case "quit": {
console.log("Bye!");
process.exit(0);
}
case "help":
default: {
console.log(
"\nCommands available\n\
--------------------------------------\n\n\
env display environment variables\n\n\
quit quit the CLI\
"
);
}
}
cli.prompt();
});