check if active tasks exists if no name is being provided before manipulating time

This commit is contained in:
Patrick Lipka 2021-12-15 17:28:44 +01:00
parent 49d3d2f1e1
commit 63abc50c81
1 changed files with 8 additions and 0 deletions

View File

@ -455,6 +455,10 @@ void command_at(std::string input, int wtime, ProjectList *proj_list){
if(place_of_slash == std::string::npos){ if(place_of_slash == std::string::npos){
if(proj_name.length()==0){ if(proj_name.length()==0){
// add time to active task // add time to active task
if(proj_list->active_project->active_task == NULL){
std::cout << "Task " << proj_list->active_project->name << "/" << proj_name << " does not exist." << std::endl;
return ;
}
proj_list->active_project->active_task->add_time(wtime); proj_list->active_project->active_task->add_time(wtime);
std::cout << wtime << "s added to task " << proj_list->active_project->name << "/" << proj_list->active_project->active_task->name << std::endl; std::cout << wtime << "s added to task " << proj_list->active_project->name << "/" << proj_list->active_project->active_task->name << std::endl;
command_save(proj_list); command_save(proj_list);
@ -496,6 +500,10 @@ void command_rt(std::string input, int wtime, ProjectList *proj_list){
if(place_of_slash == std::string::npos){ if(place_of_slash == std::string::npos){
if(proj_name.length()==0){ if(proj_name.length()==0){
// add time to active task // add time to active task
if(proj_list->active_project->active_task == NULL){
std::cout << "Task " << proj_list->active_project->name << "/" << proj_name << " does not exist." << std::endl;
return ;
}
proj_list->active_project->active_task->add_time(-wtime); proj_list->active_project->active_task->add_time(-wtime);
std::cout << wtime << "s removed from task " << proj_list->active_project->name << "/" << proj_list->active_project->active_task->name << std::endl; std::cout << wtime << "s removed from task " << proj_list->active_project->name << "/" << proj_list->active_project->active_task->name << std::endl;
return; return;