-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_command.cpp
72 lines (61 loc) · 1.83 KB
/
edit_command.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "edit_command.h"
namespace EditorParser
{
void parse_command_args(TodoServer &server, char **command_args)
{
// ./todo edit <title> <"title"|"desc"> <replacement>
std::string todo_title = command_args[0];
std::string repl_type = command_args[1];
std::string repl_str = command_args[2];
// find todo
TodoObject *todo = server.find_todo(todo_title);
if (todo == nullptr)
{
std::cout << "Couldn't find todo titled " << todo_title << std::endl;
return;
}
TodoEditor editor;
// parse type
if (repl_type.compare("title") == 0)
{
editor.edit(todo, TodoEditor::EDIT_TITLE, repl_str);
}
else if (repl_type.compare("desc") == 0)
{
editor.edit(todo, TodoEditor::EDIT_DESC, repl_str);
}
else
{
std::cout << "Please specify \"title\" or \"desc\"" << std::endl;
}
}
};
void TodoEditor::edit(TodoObject *todo, int edit_type, std::string replacement)
{
TodoTitleEditor title_editor;
TodoDescEditor desc_editor;
switch (edit_type)
{
case TodoEditor::EDIT_TITLE:
/* code */
title_editor.replace(todo, replacement);
break;
case TodoEditor::EDIT_DESC:
desc_editor.replace(todo, replacement);
break;
default:
break;
}
}
void TodoEditor::replace(TodoObject *todo, std::string replacement)
{
std::cout << "Uh oh for " << todo->get_title() << " -> " << replacement << std::endl;
}
void TodoTitleEditor::replace(TodoObject *todo, std::string replacement)
{
todo->set_title(replacement);
}
void TodoDescEditor::replace(TodoObject *todo, std::string replacement)
{
todo->set_description(replacement);
}