Add reschedule command

This commit is contained in:
augustin64 2023-07-16 09:54:32 +02:00
parent 68e7a88e5c
commit a21bac2c61
2 changed files with 44 additions and 5 deletions

View File

@ -1,7 +1,7 @@
#ifndef DEF_CONFIG_H #ifndef DEF_CONFIG_H
#define DEF_CONFIG_H #define DEF_CONFIG_H
#define VERSION "1.0.1" #define VERSION "1.0.2"
// By default, $HOME/.config/takl.sqlite3 is used. You can change this behaviour here // By default, $HOME/.config/takl.sqlite3 is used. You can change this behaviour here
//#define DB_FILE "takl.sqlite3" //#define DB_FILE "takl.sqlite3"

View File

@ -10,15 +10,17 @@
void help(char* name) { void help(char* name) {
printf(BLUE "\t-- TaKl " VERSION " --\n" RESET); printf(BLUE "\t-- TaKl " VERSION " --\n" RESET);
printf("Utilisation: %s ( list | add | info | rm | done )\n", name); printf("Utilisation: %s ( list | add | reschedule | info | rm | done )\n", name);
printf("\tlist [-a:voir les tâches complétées]\n"); printf("\tlist [-a:voir les tâches complétées]\n");
printf("\tadd <task> [date]\n"); printf("\tadd <task> [date]\n");
printf("\tFormat de la date:\n"); printf("\treschedule <id> [date]\n");
printf("\t\tRelatif: min+%%d, h+%%d, j+%%d\n");
printf("\t\tAbsolu: dd/mm (pas de changement d'année pour l'instant)\n");
printf("\tinfo <id1> <id2> ...\n"); printf("\tinfo <id1> <id2> ...\n");
printf("\tdone <id1> <id2> ...\n"); printf("\tdone <id1> <id2> ...\n");
printf("\trm <id1> <id2> ...\n"); printf("\trm <id1> <id2> ...\n");
printf("\nFormat des dates:\n");
printf("\tRelatif: min+%%d, h+%%d, j+%%d\n");
printf("\tAbsolu: dd/mm (pas de changement d'année pour l'instant)\n");
} }
@ -98,6 +100,41 @@ int add(int argc, char* argv[]) {
return 0; return 0;
} }
int reschedule(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(YELLOW "Tâche " BOLD "[%d]" RESET YELLOW " inexistante. Vérifiez que l'identifiant est bien correct\n" RESET, id);
return 1;
}
time_t due_to = parseDateTime(argv[3]);
if (due_to == -1) {
printf(RED "Échéance invalide, impossible de reprogrammer la tâche.\n" RESET);
return 1;
}
t.due_to = due_to;
if (update_task(t) != 0) {
printf("Erreur lors de la modification de la tâche\n");
return 1;
}
return 0;
}
int list_tasks(bool show_completed) { int list_tasks(bool show_completed) {
task_list_t* tasks = get_task_list(show_completed); task_list_t* tasks = get_task_list(show_completed);
print_task_list(tasks, show_completed); // show_completed: true would work as all the tasks are not loaded if false print_task_list(tasks, show_completed); // show_completed: true would work as all the tasks are not loaded if false
@ -195,6 +232,8 @@ int main(int argc, char* argv[]) {
if (!strcmp(argv[1], "add")) { if (!strcmp(argv[1], "add")) {
return add(argc, argv); return add(argc, argv);
} else if (!strcmp(argv[1], "reschedule")) {
return reschedule(argc, argv);
} else if (!strcmp(argv[1], "list")) { } else if (!strcmp(argv[1], "list")) {
return list_tasks(argc > 2 && !strcmp(argv[2], "-a")); return list_tasks(argc > 2 && !strcmp(argv[2], "-a"));
} else if (!strcmp(argv[1], "info")) { } else if (!strcmp(argv[1], "info")) {