Add safeguards to avoid bad usage.

This commit is contained in:
Nicolás A. Ortega Froysa 2024-10-29 17:59:57 +01:00
parent a3b6471c13
commit 4379b0311e
2 changed files with 25 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# To-Do List
- [ ] Add more safeguards to avoid bad usage.
- [X] Add more safeguards to avoid bad usage.
- [ ] Create a man page.
- [ ] Add more documentation to `help` subcommand.
- [ ] Add import/export functionality.

View File

@ -39,39 +39,63 @@ int main(int argc, char *argv[]) {
try {
switch(id) {
case CMD_ADD:
if(argc not_eq 2)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
ret = cmd_add();
break;
case CMD_DEL:
if(argc not_eq 3)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
ret = cmd_delete(argc - 2, argv + 2);
break;
case CMD_LIST:
if(argc > 6)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
ret = cmd_list(argc - 1, argv + 1);
break;
case CMD_INFO:
if(argc not_eq 3)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
ret = cmd_info(std::stoi(argv[2]));
break;
case CMD_EDIT_NAME:
if(argc not_eq 3)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
ret = cmd_edit_name(std::stoi(argv[2]));
break;
case CMD_EDIT_DESC:
if(argc not_eq 3)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
ret = cmd_edit_desc(std::stoi(argv[2]));
break;
case CMD_ADD_INGR:
if(argc not_eq 4)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
ret = cmd_add_ingr(std::stoi(argv[2]), argv[3]);
break;
case CMD_RM_INGR:
if(argc not_eq 4)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
ret = cmd_rm_ingr(std::stoi(argv[2]), argv[3]);
break;
case CMD_ADD_TAG:
if(argc not_eq 4)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
ret = cmd_add_tag(std::stoi(argv[2]), argv[3]);
break;
case CMD_RM_TAG:
if(argc not_eq 4)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
ret = cmd_rm_tag(std::stoi(argv[2]), argv[3]);
break;
case CMD_HELP:
if(argc not_eq 2)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
print_help();
break;
case CMD_VERSION:
if(argc not_eq 2)
throw "Invalid number of arguments. Use 'help' subcommand for more information.";
print_version();
break;
default: