Added convert command to convert old to new tracking files

This commit is contained in:
Patrick Lipka 2022-04-05 13:51:26 +02:00
parent 78cd47992b
commit f65930216f
2 changed files with 20 additions and 1 deletions

View File

@ -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;

View File

@ -5,7 +5,7 @@
#include <string>
#include "project.h"
const int num_commands=14;
const int num_commands=15;
extern std::string command_names[num_commands];
extern std::vector<std::string> 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