-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.cpp
More file actions
164 lines (123 loc) · 3.86 KB
/
Command.cpp
File metadata and controls
164 lines (123 loc) · 3.86 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "Command.hpp"
using namespace std;
void backup::command::command(std::vector<std::string> vector_argv)
{
backup::system::Error_Code error_code;
if (!backup::command::is_right(vector_argv, error_code))
{
cout << "[알림] >> " << error_code.what() << endl << endl;
return;
}
switch (backup::command::get_work(vector_argv))
{
case backup::command::work::add:
backup::dir_center::add(backup::command::get_source_path(vector_argv), backup::command::get_dest_path(vector_argv));
break;
case backup::command::work::_delete:
backup::dir_center::_delete();
break;
case backup::command::work::print:
backup::dir_center::print();
break;
case backup::command::work::sync:
cout << "[알림] >> 다음 항목을 동기화 합니다." << endl << endl;
{
vector<string> str_paths;
if (backup::dir_center::print(&str_paths))
return;
for (int index = 0; index < str_paths.size(); index++)
backup::sync::sync(backup::dir_center::get_source_path(str_paths[index]),
backup::dir_center::get_dest_path(str_paths[index]));
}
cout << "[알림] >> 동기화가 끝났습니다." << endl << endl;
break;
case backup::command::work::help:
//
break;
}
}
backup::command::work backup::command::get_work(std::vector<std::string> vector_argv)
{
string work = vector_argv[1];
if (work == "add")
return backup::command::work::add;
else if (work == "delete")
return backup::command::work::_delete;
else if (work == "print")
return backup::command::work::print;
else if (work == "sync")
return backup::command::work::sync;
else if (work == "help")
return backup::command::work::help;
else
return backup::command::work::unknown;
}
bfs::path backup::command::get_source_path(std::vector<std::string> vector_argv)
{
int index = 0;
if (vector_argv[2] == "-root")
index = 3;
else if (vector_argv[4] == "-root")
index = 5;
bfs::path root(vector_argv[index]);
return root.generic_string();
}
bfs::path backup::command::get_dest_path(std::vector<std::string> vector_argv)
{
int index = 0;
if (vector_argv[2] == "-dest")
index = 3;
else if (vector_argv[4] == "-dest")
index = 5;
bfs::path dest(vector_argv[index]);
return dest.generic_string();
}
bool backup::command::is_right(std::vector<std::string> vector_argv, backup::system::Error_Code& error_code)
{
// main의 argv의 개수가 1개 이면 오류 문장이다.
if (vector_argv.size() == 1)
{
error_code.set_error_code(backup::system::error_list::number_of_element);
return false;
}
switch (backup::command::get_work(vector_argv))
{
// work == unknown일 때 오류 문장이다.
case backup::command::work::unknown:
error_code.set_error_code(backup::system::error_list::nonexistent_work);
return false;
// work이 print, delete, help (옵션이 없는 work)일 때
case backup::command::work::print:
case backup::command::work::_delete:
case backup::command::work::sync:
case backup::command::work::help:
// 명령어의 길이가 2가 아니면 오류 문장이다.
if (vector_argv.size() != 2)
{
error_code.set_error_code(backup::system::error_list::number_of_element);
return false;
}
return true;
// work이 add일 때
case backup::command::work::add:
// 명령어의 길이가 6개가 아니면 오류 문장이다.
if (vector_argv.size() != 6)
{
error_code.set_error_code(backup::system::error_list::number_of_element);
return false;
}
// 옵션 자리에 -root, -dest가 없으면 오류 문장이다.
if (!((vector_argv[2] == "-root") || (vector_argv[4] == "-root") && ((vector_argv[2] == "-dest") || (vector_argv[4] == "-dest"))))
{
error_code.set_error_code(backup::system::error_list::nonexistent_option);
return false;
}
// 경로가 존재하지 않으면 오류 문장이다.
if (!bfs::exists(backup::command::get_source_path(vector_argv)) || !bfs::exists(backup::command::get_dest_path(vector_argv)))
{
error_code.set_error_code(backup::system::error_list::nonexistent_path);
return false;
}
return true;
}
}