-
Notifications
You must be signed in to change notification settings - Fork 0
/
notex.cpp
45 lines (40 loc) · 1.38 KB
/
notex.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 "notex.hpp"
int main(int argc, char const *argv[]) {
alib::clrscr();
alib::decorateMe("Notex", 1, "", true);
// Creating database & Table
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
std::string home = homedir;
std::string dbfile = home + "/.local/share/data.db";
const char *dbfilename = dbfile.c_str();
const char *tbname = "general";
Database *db = new Database();
if (argc >= 2) {
const char *availableCommands[] = {"-p", "--print"};
if (std::strcmp(argv[1], availableCommands[0]) == 0 ||
std::strcmp(argv[1], availableCommands[1]) ==
0) { /* -p || --print option */
db->printNotexData(dbfilename, tbname);
} else {
alib::horizontalLine(1, "red");
std::cout << rang::fg::red << "Inavlid Arguments Passed"
<< rang::fg::reset << std::endl;
alib::horizontalLine(1, "red");
}
} else {
db->createDb(dbfilename);
db->createNotexTable(dbfilename, tbname);
std::string note;
std::cout << "Extra Notes: ";
getline(std::cin, note);
bool queryStatus = db->insertNotexData(dbfilename, tbname, note.c_str());
if (queryStatus)
alib::decorateMe("Records kept successfully", 0, "*");
else
std::cerr << rang::fg::red << "Errors occured ! Couldn't store data"
<< rang::fg::reset << std::endl;
}
delete db;
return 0;
}