From 54ec5262d3db21c65ffd62b7719f6a6bed64c498 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 12 Jul 2023 21:29:17 +0200 Subject: [PATCH] And the corresponding main.c --- src/main.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 178e346..70ab879 100644 --- a/src/main.c +++ b/src/main.c @@ -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]);