And the corresponding main.c

This commit is contained in:
augustin64 2023-07-12 21:29:17 +02:00
parent 33f77d4cfc
commit 54ec5262d3

View File

@ -70,7 +70,7 @@ int add(int argc, char* argv[]) {
if (argc < 3) {
printf(BOLD YELLOW "Argument manquant\n" RESET);
help(argv[0]);
return 1; // TODO: trouver le bon code d'erreur
return 1;
}
time_t due_to = 0;
@ -110,7 +110,7 @@ int info(int argc, char* argv[]) {
if (t.id == -1) {
printf(BOLD YELLOW "Tâche inexistante. Vérifiez que l'identifiant est bien correct\n" RESET);
exit(1);
return 1;
}
print_task(t);
@ -119,8 +119,57 @@ int info(int argc, char* argv[]) {
return 0;
}
int mark_done(int argc, char* argv[]) {
if (argc < 3) {
printf(BOLD YELLOW "Argument manquant\n" RESET);
help(argv[0]);
return 1;
}
int id = strtol(argv[2], NULL, 10);
task_t t;
t.id = -1;
get_task(id, &t);
if (t.id == -1) {
printf(BOLD YELLOW "Tâche inexistante. Vérifiez que l'identifiant est bien correct\n" RESET);
return 1;
}
t.done = true;
update_task(t);
return 0;
}
int delete(int argc, char* argv[]) {
if (argc < 3) {
printf(BOLD YELLOW "Argument manquant\n" RESET);
help(argv[0]);
return 1;
}
int id = strtol(argv[2], NULL, 10);
task_t t;
t.id = -1;
get_task(id, &t);
if (t.id == -1) {
printf(BOLD YELLOW "Tâche inexistante. Vérifiez que l'identifiant est bien correct\n" RESET);
return 1;
}
delete_task(t.id);
return 0;
}
int main(int argc, char* argv[]) {
srand(time(NULL));
if (argc <= 1) {
help(argv[0]);
return 0;
@ -132,12 +181,10 @@ int main(int argc, char* argv[]) {
return list_tasks();
} else if (!strcmp(argv[1], "info")) {
return info(argc, argv);
} else if (!strcmp(argv[1], "done")) { //TODO
printf("Not Implemented\n");
return 1;
} else if (!strcmp(argv[1], "rm")) { //TODO
printf("Not Implemented\n");
return 1;
} else if (!strcmp(argv[1], "done")) {
return mark_done(argc, argv);
} else if (!strcmp(argv[1], "rm")) {
return delete(argc, argv);
}
printf(YELLOW "Option invalide " BOLD "%s\n" RESET, argv[1]);