-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·114 lines (97 loc) · 3.16 KB
/
index.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env node
import { Command } from "commander";
import inquirer from "inquirer";
import addPass from "./commands/PassCommands/addPass.js";
import listPass from "./commands/PassCommands/listPass.js";
import updatePass from "./commands/PassCommands/updatePass.js";
import deletePass from "./commands/PassCommands/deletePass.js";
import addTodo from "./commands/TodoCommands/addTodo.js";
import listTodo from "./commands/TodoCommands/listTodo.js";
import updateTodo from "./commands/TodoCommands/updateTodo.js";
import deleteTodo from "./commands/TodoCommands/deleteTodo.js";
const program = new Command();
program
.name("Cli-Manager")
.description("Cli Tool to manage Todo & Passwords ")
.version("1.0.0");
const chooseCategory = async () => {
const { category } = await inquirer.prompt([
{
type: "list",
name: "category",
message: "What would you like to manage?",
choices: ["Passwords", "Todos", "Exit"],
},
]);
if (category === "Exit") {
console.log("GoodBye!");
process.exit(0);
}
return category;
};
const setupCommands = (category) => {
program.commands = [];
if (category === "Passwords") {
program
.command("Add")
.description("Add a new Password")
.action(addPass);
program
.command("List")
.description("List all Passwords")
.action(listPass);
program
.command("Update")
.description("Update a Password")
.action(updatePass);
program
.command("Delete")
.description("Delete a Password")
.action(deletePass);
} else if (category === "Todos") {
program.command("Add").description("Add a new Todo").action(addTodo);
program.command("List").description("List all Todos").action(listTodo);
program
.command("Update")
.description("Update a Todo")
.action(updateTodo);
program
.command("Delete")
.description("Delete a Todo")
.action(deleteTodo);
}
};
const promptForCommand = async () => {
const { command } = await inquirer.prompt([
{
type: "list",
name: "command",
message: "What would you like to do?",
choices: ["Add", "List", "Update", "Delete", "Exit"],
},
]);
if (command === "Exit") {
console.log("GoodBye!");
process.exit(0);
}
return command;
};
const main = async () => {
const category = await chooseCategory();
setupCommands(category);
console.log(
`You've selected ${category}. Available commands: Add, List, Update, Delete`
);
const command = await promptForCommand();
try {
await program.parseAsync([process.argv[0], process.argv[1], command]);
} catch (error) {
console.error("Error executing command:", error.message);
}
console.log("Operation completed. Exiting program.");
process.exit(0);
};
main().catch((error) => {
console.error("An unexpected error occurred:", error.message);
process.exit(1);
});