From f65930216f1fd962acd389d6779222ccdbfd4f33 Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Tue, 5 Apr 2022 13:51:26 +0200 Subject: [PATCH] Added convert command to convert old to new tracking files --- src/ui.cpp | 18 ++++++++++++++++++ src/ui.h | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ui.cpp b/src/ui.cpp index adca560..f0a161d 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -30,6 +30,7 @@ std::string command_names[num_commands]={ "start", "save", "load", + "convert", "version" }; @@ -187,6 +188,13 @@ void parse_input(std::string input, ProjectList *proj_list){ }else{ command_load(argument,proj_list); } + }else if (command == "convert"){ + if(command_end == std::string::npos){ + std::cout << "convert: please specify tracking file to convert (format: yyyy-mm)" << std::endl; + }else{ + command_convert(argument); + } + }else if (command == "version"){ command_version(); } @@ -645,6 +653,16 @@ void command_load(std::string date_str, ProjectList* proj_list){ std::cout << "Loaded project data for month " << proj_list->month << std::endl << std::endl; } +// convert previous tracking file version to current one +void command_convert(std::string date_str){ + date_str = trim(date_str); + ProjectList list(date_str); + std::string file_name = tracking_dir+"/"+date_str; + list.load(file_name); + list.save(file_name); + std::cout << "Successfully converted data file" << file_name << std::endl; +} + // print version number void command_version(){ std::cout << "tt v." << STRING(TT_VERSION) << std::endl; diff --git a/src/ui.h b/src/ui.h index a238a82..2a5aaf9 100644 --- a/src/ui.h +++ b/src/ui.h @@ -5,7 +5,7 @@ #include #include "project.h" -const int num_commands=14; +const int num_commands=15; extern std::string command_names[num_commands]; extern std::vector autocomplete_names; char **tt_name_completion(const char* text, int start, int end); @@ -31,5 +31,6 @@ void command_rt(std::string input, int wtime, ProjectList *proj_list); void command_report(std::string date_str, ProjectList *proj_list); void command_save(ProjectList *proj_list); void command_load(std::string date_str, ProjectList *proj_list); +void command_convert(std::string date_str); void command_version(); #endif