menu-helper/src/main.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

2024-09-05 20:59:41 +02:00
/*
* Copyright (C) 2024 Nicolás Ortega Froysa <nicolas@ortegas.org>
* Nicolás Ortega Froysa <nicolas@ortegas.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2024-10-09 20:03:10 +02:00
#include <iostream>
#include <cstdlib>
2024-10-11 12:01:22 +02:00
#include <string>
2024-09-05 20:59:41 +02:00
2024-10-09 19:50:53 +02:00
#include "arg_parse.hpp"
#include "cmd.hpp"
2024-09-05 20:59:41 +02:00
int main(int argc, char *argv[]) {
enum cmd_id id;
2024-10-11 09:24:48 +02:00
int ret = EXIT_SUCCESS;
2024-09-05 20:59:41 +02:00
if(argc < 2) {
2024-10-09 20:03:10 +02:00
std::cerr << "Invalid number of arguments. Use 'help' sub-command." << std::endl;
2024-09-05 20:59:41 +02:00
print_usage();
return EXIT_FAILURE;
}
id = parse_args(argv[1]);
switch(id) {
case CMD_ADD:
2024-10-11 16:18:22 +02:00
ret = cmd_add();
2024-10-11 09:24:48 +02:00
break;
case CMD_LIST:
2024-10-11 16:18:22 +02:00
ret = cmd_list(argc - 1, argv + 1);
break;
2024-10-11 10:43:38 +02:00
case CMD_DEL:
2024-10-11 16:18:22 +02:00
ret = cmd_delete(argc - 2, argv + 2);
2024-10-11 10:43:38 +02:00
break;
2024-10-11 12:01:22 +02:00
case CMD_INFO:
2024-10-11 16:18:22 +02:00
ret = cmd_info(std::stoi(argv[2]));
2024-10-11 12:01:22 +02:00
break;
2024-09-05 20:59:41 +02:00
case CMD_HELP:
print_help();
break;
case CMD_VERSION:
print_version();
break;
default:
2024-10-09 20:03:10 +02:00
std::cerr << "No such command '" << argv[1] << "'. Use 'help' sub-command." << std::endl;
2024-09-05 20:59:41 +02:00
print_usage();
return EXIT_FAILURE;
}
2024-10-11 09:24:48 +02:00
return ret;
2024-09-05 20:59:41 +02:00
}