-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
45 lines (43 loc) · 1.58 KB
/
main.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
#include "archiver_main/archiver_main.h"
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main(int argc, char* argv[]) {
Archiver archiver;
if (argc == 1) {
std::cout << "Unknown command! Type -h to help." << std::endl;
} else {
std::string command = argv[1];
if (command == "-h") {
archiver.Help();
} else if (command == "-c") {
if (argc == 2) {
std::cout << "You didn't type archive's name! Type -h to help." << std::endl;
} else {
std::string archive_name = argv[2];
if (argc == 3) {
std::cout << "You didn't select any files! Type -h to help." << std::endl;
} else {
std::vector<std::string> files_to_archive;
for (int i = 3; i < argc; ++i) {
files_to_archive.push_back(argv[i]);
}
archiver.Archive(archive_name, files_to_archive);
}
}
} else if (command == "-d") {
if (argc == 2) {
std::cout << "You didn't select any files! Type -h to help." << std::endl;
} else if (argc > 3) {
std::cout << "You have selected too many files. Type -h to help." << std::endl;
} else {
std::string file_to_dearchive = argv[2];
archiver.Dearchive(file_to_dearchive);
}
} else {
std::cout << "Unknown command! Type -h to help." << std::endl;
}
}
return 0;
}