-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (70 loc) · 1.6 KB
/
main.cpp
File metadata and controls
85 lines (70 loc) · 1.6 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
#include <iostream>
#include <fstream>
#include <filesystem>
#include <vector>
#include <string>
#include "Commands.h";
using namespace std;
namespace fs = filesystem;
void printUsage() {
cout << "MiniAWS RAID Controller CLI" << endl;
cout << "Usage:" << endl;
cout << "raid.exe --write <fileName>" << endl;
cout << "raid.exe --read <fileName>" << endl;
cout << "Example: raid.exe --write test_photo.jpg" << endl;
}
int main(int argc, char* argv[]){
if (argc < 3) {
printUsage();
return 1;
}
string command;
string fileName;
string customBaseDir = "";
// parse the command line inputs
for (int i = 1; i < argc; i++) {
string arg = argv[i];
if (arg == "--base-dir" && i + 1 < argc) {
i++;
customBaseDir = argv[i];
}
else if (command.empty()) {
command = arg;
}
else if (fileName.empty()) {
fileName = arg;
}
}
if (command.empty() || fileName.empty()) {
cerr << "ERROR | Missing command or filename" << endl;
printUsage();
return 1;
}
// fallback to default
if (customBaseDir.empty()) {
customBaseDir = "E:\\MiniAWS\\";
}
try {
Commands commandHandler(customBaseDir);
commandHandler.init();
if (command == "--write") {
commandHandler.handleWrite(fileName);
}
else if (command == "--read") {
commandHandler.handleRead(fileName);
}
else if (command == "--delete") {
commandHandler.handleDelete(fileName);
}
else {
cerr << "ERROR | Command not recognized: " << command << endl;
printUsage();
return 1;
}
}
catch (const exception& err) {
cerr << "ERROR | Command execution failed: " << err.what() << endl;
return 1;
}
return 0;
}