migrate to c++, all layers done except for data access
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#include "include/parser.h"
|
||||
#include "include/handler.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void show_usage() {
|
||||
cout << "usage:\n"
|
||||
"these env vars have to be set: FRONTEND_API_KEY, DB_URL"
|
||||
"tickets create <title> <description>\n"
|
||||
"tickets list [-status <status>]\n"
|
||||
"tickets detail <id>" << endl;
|
||||
}
|
||||
|
||||
#define show_usage_and_die() show_usage(); return 1;
|
||||
|
||||
int parse_args(Dao *dao, int argc, char *argv[]) {
|
||||
if (argc == 1) { // not enough args
|
||||
show_usage_and_die();
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "create") == 0) { // creating a ticket
|
||||
if (argc != 4) {
|
||||
show_usage_and_die();
|
||||
}
|
||||
|
||||
return handle_create(dao, argv[2], argv[3]); // title and description
|
||||
}
|
||||
|
||||
|
||||
if (strcmp(argv[1], "list") == 0) { // listing tickets (optional filter by status)
|
||||
if (argc != 2 || argc != 4) {
|
||||
show_usage_and_die();
|
||||
}
|
||||
|
||||
if (argc == 4) {
|
||||
if (strcmp(argv[2], "-status") == 0) {
|
||||
return handle_list(dao, argv[3]); // the status text
|
||||
}
|
||||
}
|
||||
|
||||
// now we know that argc == 2
|
||||
// -> handle list (get all tickets)
|
||||
return handle_list(dao);
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "detail") == 0) {
|
||||
if (argc != 3) {
|
||||
show_usage_and_die();
|
||||
}
|
||||
|
||||
int ticket_id = atoi(argv[2]);
|
||||
|
||||
return handle_detail(dao, ticket_id); // ticket id
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user