Run pre-commit on files

This commit is contained in:
realaltffour 2020-04-05 14:54:23 +03:00
parent 5eae19af68
commit 63ad0d6ba1
No known key found for this signature in database
GPG Key ID: 05B35E2E8F56C5A6
12 changed files with 18761 additions and 19678 deletions

View File

@ -5,7 +5,7 @@ on: [push]
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: build - name: build

View File

@ -5,7 +5,7 @@ on: [push]
jobs: jobs:
build: build:
runs-on: macOS-latest runs-on: macOS-latest
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: build - name: build

View File

@ -33,5 +33,5 @@ file(GLOB_RECURSE skidjular_srcs "src/*.cpp")
include_directories("src/") include_directories("src/")
include_directories("vendor/") include_directories("vendor/")
add_executable(skidjular ${skidjular_hdrs} ${skidjular_srcs}) add_executable(skidjular ${skidjular_hdrs} ${skidjular_srcs})
target_link_libraries(skidjular ${CONAN_LIBS}) target_link_libraries(skidjular ${CONAN_LIBS})

View File

@ -3,7 +3,7 @@
## How to Contribute ## How to Contribute
When contributing to this repository, please first discuss the change you wish to make via issue, When contributing to this repository, please first discuss the change you wish to make via issue,
email, or any other method with the owners of this repository before making a change. email, or any other method with the owners of this repository before making a change.
## Pull requests ## Pull requests
@ -11,4 +11,4 @@ When submitting a pull request:
1. Clone the repo. 1. Clone the repo.
2. Create a branch off of `master` and give it a meaningful name (e.g. `my-awesome-new-feature`) and describe the feature or fix. 2. Create a branch off of `master` and give it a meaningful name (e.g. `my-awesome-new-feature`) and describe the feature or fix.
3. Open a pull request on GitHub. 3. Open a pull request on GitHub.

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
mkdir build mkdir build
cd build cd build
conan install .. --build missing conan install .. --build missing

View File

@ -1,81 +1,72 @@
#include "data.h" #include "data.h"
void to_json(json& j, const Date& date) { void to_json(json& j, const Date& date) {
j = json{ j = json{{"day", date.day}, {"month", date.day}, {"year", date.year}};
{"day", date.day},
{"month", date.day},
{"year", date.year}
};
} }
void from_json(const json& j, Date& date) { void from_json(const json& j, Date& date) {
j.at("day").get_to(date.day); j.at("day").get_to(date.day);
j.at("month").get_to(date.month); j.at("month").get_to(date.month);
j.at("year").get_to(date.year); j.at("year").get_to(date.year);
} }
void to_json(json& j, const Project& proj) { void to_json(json& j, const Project& proj) {
j = json{ j = json{{"name", proj.name},
{"name", proj.name}, {"desc", proj.desc},
{"desc", proj.desc}, {"uuid", proj.uuid},
{"uuid", proj.uuid}, {"pri", proj.pri},
{"pri", proj.pri}, {"creationDate", proj.creationDate},
{"creationDate", proj.creationDate}, {"doneDate", proj.doneDate},
{"doneDate", proj.doneDate}, {"isDone", proj.isDone}};
{"isDone", proj.isDone}
};
} }
void from_json(const json& j, Project& proj) { void from_json(const json& j, Project& proj) {
j.at("name").get_to(proj.name); j.at("name").get_to(proj.name);
j.at("desc").get_to(proj.desc); j.at("desc").get_to(proj.desc);
j.at("uuid").get_to(proj.uuid); j.at("uuid").get_to(proj.uuid);
j.at("pri").get_to(proj.pri); j.at("pri").get_to(proj.pri);
j.at("creationDate").get_to(proj.creationDate); j.at("creationDate").get_to(proj.creationDate);
j.at("doneDate").get_to(proj.doneDate); j.at("doneDate").get_to(proj.doneDate);
j.at("isDone").get_to(proj.isDone); j.at("isDone").get_to(proj.isDone);
} }
void to_json(json& j, const Skid& skid) { void to_json(json& j, const Skid& skid) {
j = json{ j = json{
{"projects", *skid.projects}, {"projects", *skid.projects},
{"creationDate", skid.creationDate}, {"creationDate", skid.creationDate},
}; };
} }
void from_json(const json& j, Skid& skid) { void from_json(const json& j, Skid& skid) {
j.at("projects").get_to(*skid.projects); j.at("projects").get_to(*skid.projects);
j.at("creationDate").get_to(skid.creationDate); j.at("creationDate").get_to(skid.creationDate);
} }
void to_json(json& j, const DB& db) { void to_json(json& j, const DB& db) {
j = json{ j = json{{"projects", *db.projects},
{"projects", *db.projects}, {"creationDate", db.creationDate},
{"creationDate", db.creationDate}, {"lastAccessTime", db.lastAccessTime}};
{"lastAccessTime", db.lastAccessTime}
};
} }
void from_json(const json& j, DB& db) { void from_json(const json& j, DB& db) {
j.at("projects").get_to(*db.projects); j.at("projects").get_to(*db.projects);
j.at("creationDate").get_to(db.creationDate); j.at("creationDate").get_to(db.creationDate);
j.at("lastAccessTime").get_to(db.lastAccessTime); j.at("lastAccessTime").get_to(db.lastAccessTime);
} }
void writeDB(DB db, const std::string& dest) {
void writeDB(DB db, const std::string &dest) { try {
try { std::ofstream f(dest);
std::ofstream f(dest); json j = db;
json j = db; std::cout << "hello" << std::endl;
std::cout << "hello" << std::endl; f << j;
f << j; } catch(std::exception& ex) {
} catch (std::exception &ex) { std::cout << "Failed writing database to: " << dest << std::endl;
std::cout << "Failed writing database to: " << dest << std::endl; std::cout << "Error: " << ex.what() << std::endl;
std::cout << "Error: " << ex.what() << std::endl; }
}
} }
void loadDB(DB &db, const std::string &src) { void loadDB(DB& db, const std::string& src) {
try { try {
std::ifstream f(src); std::ifstream f(src);
json j; json j;
f >> j; f >> j;
db = j; db = j;
} catch (const std::exception& ex) { } catch(const std::exception& ex) {
std::cout << "Failed loading database from: " << src << std::endl; std::cout << "Failed loading database from: " << src << std::endl;
std::cout << "Error: " << ex.what() << std::endl; std::cout << "Error: " << ex.what() << std::endl;
} }
} }

View File

@ -10,31 +10,31 @@
#include "json.hpp" #include "json.hpp"
using nlohmann::json; using nlohmann::json;
#define LOC_DB = ".db" #define LOC_DB = ".db"
#define LOC_EVENTLOG = ".log" #define LOC_EVENTLOG = ".log"
#define LOC_SKIDID = "skid" // used as LOC_SKIDID+SKIDNUM #define LOC_SKIDID = "skid" // used as LOC_SKIDID+SKIDNUM
/////////////// DATA CONTAINING STRUCTURES /////////////////// /////////////// DATA CONTAINING STRUCTURES ///////////////////
struct Date { struct Date {
int day = 0; int day = 0;
int month = 0; // 0-11 int month = 0; // 0-11
int year = 0; // + 1900 for currentyear int year = 0; // + 1900 for currentyear
}; };
struct Project { struct Project {
std::string name = ""; std::string name = "";
std::string desc = ""; std::string desc = "";
std::string uuid; std::string uuid;
int pri = 0; int pri = 0;
Date creationDate; Date creationDate;
Date doneDate; Date doneDate;
bool isDone = false; bool isDone = false;
}; };
struct Skid { struct Skid {
std::vector<Project> *projects = {}; std::vector<Project>* projects = {};
Date creationDate; Date creationDate;
}; };
/////////////// END OF DATA CONTAINING STRUCTURES //////////// /////////////// END OF DATA CONTAINING STRUCTURES ////////////
@ -44,32 +44,32 @@ struct Skid {
enum EventType { Access = 0, Creation = 1, Modification = 2, None = -1 }; enum EventType { Access = 0, Creation = 1, Modification = 2, None = -1 };
struct Event { struct Event {
int id = -1; int id = -1;
EventType type = EventType::None; EventType type = EventType::None;
std::string mesg = ""; std::string mesg = "";
}; };
struct EventLog { struct EventLog {
std::vector<Event> *events; std::vector<Event>* events;
std::string sha512 = ""; std::string sha512 = "";
}; };
/////////////// EVENT END OF HISTORY SYSTEM STRUCTURES ///////////// /////////////// EVENT END OF HISTORY SYSTEM STRUCTURES /////////////
// Main Database that represents the skidjular directory. // Main Database that represents the skidjular directory.
struct DB { struct DB {
std::map<std::string, Project> *projects; std::map<std::string, Project>* projects;
std::vector<Skid> skids; std::vector<Skid> skids;
EventLog log; EventLog log;
Date creationDate; Date creationDate;
Date lastAccessTime; Date lastAccessTime;
}; };
////////////// Utilities for the Database structure //////////////// ////////////// Utilities for the Database structure ////////////////
void writeDB(DB db, const std::string &dest); void writeDB(DB db, const std::string& dest);
void loadDB(DB &db, const std::string &src); void loadDB(DB& db, const std::string& src);
////////////// End Utilities for the Database structure //////////// ////////////// End Utilities for the Database structure ////////////

View File

@ -7,62 +7,63 @@
#include "module.h" #include "module.h"
#include "modules/init.h" #include "modules/init.h"
Module* get_Mod(std::string name) {return nullptr;}; Module* get_Mod(std::string name) {
void dispatch_Mod(Module* mod, std::string args) {}; return nullptr;
};
void dispatch_Mod(Module* mod, std::string args){};
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace boost::program_options; using namespace boost::program_options;
using namespace std; using namespace std;
try { try {
options_description general("General Options"); options_description general("General Options");
general.add_options()("help", "Help Message")( general.add_options()("help", "Help Message")(
"help-module", value<string>(), "Module for help message")( "help-module", value<string>(), "Module for help message")(
"module", value<string>(), "Module to execute")( "module", value<string>(), "Module to execute")(
"module-args", value<string>(), "Arguments to use"); "module-args", value<string>(), "Arguments to use");
positional_options_description general_positional; positional_options_description general_positional;
general_positional.add("module", 1); general_positional.add("module", 1);
general_positional.add("module-args", 10); general_positional.add("module-args", 10);
variables_map vm; variables_map vm;
store(command_line_parser(argc, argv) store(command_line_parser(argc, argv)
.options(general) .options(general)
.allow_unregistered() .allow_unregistered()
.positional(general_positional) .positional(general_positional)
.run(), .run(),
vm); vm);
notify(vm); notify(vm);
if (vm.count("help")) { if(vm.count("help")) {
std::cout << general << "\n"; std::cout << general << "\n";
exit(0); exit(0);
} else if (vm.count("help-module")) { } else if(vm.count("help-module")) {
auto name = vm["help-module"].as<string>(); auto name = vm["help-module"].as<string>();
auto module = get_Mod(name); auto module = get_Mod(name);
if (!module) { if(!module) {
std::cout << "Module not found.\n"; std::cout << "Module not found.\n";
exit(1); exit(1);
} }
std::cout << module->desc << "\n"; std::cout << module->desc << "\n";
} else if (vm.count("module")) { } else if(vm.count("module")) {
auto name = vm["module"].as<string>(); auto name = vm["module"].as<string>();
auto module = get_Mod(name); auto module = get_Mod(name);
if (!module) { if(!module) {
std::cout << "Module not found.\n"; std::cout << "Module not found.\n";
exit(1); exit(1);
} }
if (vm.count("module-args")) { if(vm.count("module-args")) {
auto args = vm["module-args"].as<string>(); auto args = vm["module-args"].as<string>();
dispatch_Mod(module, args); dispatch_Mod(module, args);
} else dispatch_Mod(module, ""); } else
dispatch_Mod(module, "");
} else { } else {
std::cout << general << "\n"; std::cout << general << "\n";
exit(0); exit(0);
} }
} catch (const error& ex) { } catch(const error& ex) { cerr << ex.what() << '\n'; }
cerr << ex.what() << '\n';
}
return 0; return 0;
} }

View File

@ -5,13 +5,13 @@
#include <map> #include <map>
#include <string> #include <string>
using ModuleFn = std::function<void(std::string arguments)>; using ModuleFn = std::function<void(std::string arguments)>;
using ModuleFnDispatcher = std::function<void(std::string arguments)>; using ModuleFnDispatcher = std::function<void(std::string arguments)>;
struct Module { struct Module {
std::string name; std::string name;
std::string desc; std::string desc;
std::map<std::string, ModuleFn> funcs; std::map<std::string, ModuleFn> funcs;
}; };
#endif #endif

View File

@ -3,35 +3,35 @@
#include "../data.h" #include "../data.h"
void init_create(init_args arg) { void init_create(init_args arg) {
std::cout << "Creating database in current directory." << std::endl; std::cout << "Creating database in current directory." << std::endl;
DB db; DB db;
time_t t = time(0); time_t t = time(0);
struct tm *currentTime = localtime(&t); struct tm* currentTime = localtime(&t);
db.creationDate.day = currentTime->tm_mday; db.creationDate.day = currentTime->tm_mday;
db.creationDate.month = currentTime->tm_mon; db.creationDate.month = currentTime->tm_mon;
db.creationDate.year = currentTime->tm_year; db.creationDate.year = currentTime->tm_year;
db.lastAccessTime.day = currentTime->tm_mday; db.lastAccessTime.day = currentTime->tm_mday;
db.lastAccessTime.month = currentTime->tm_mon; db.lastAccessTime.month = currentTime->tm_mon;
db.lastAccessTime.year = currentTime->tm_year; db.lastAccessTime.year = currentTime->tm_year;
// Mandatory stuff to stop segmantion fault due to // Mandatory stuff to stop segmantion fault due to
// pointers unintialized. // pointers unintialized.
db.projects = new std::map<std::string, Project>(); db.projects = new std::map<std::string, Project>();
db.log.events = new std::vector<Event>(); db.log.events = new std::vector<Event>();
// TODO: Add event logging // TODO: Add event logging
writeDB(db, ".db"); writeDB(db, ".db");
} }
void init_dispatch() { void init_dispatch() {
init_args arg; init_args arg;
init_create(arg); init_create(arg);
} }
init_mod init_new() { init_mod init_new() {
init_mod mod; init_mod mod;
mod.name = "Init"; mod.name = "Init";
mod.desc = "Creates skidjular directory in $(pwd)"; mod.desc = "Creates skidjular directory in $(pwd)";
return mod; return mod;
} }

View File

@ -12,7 +12,7 @@ struct init_args {};
struct init_mod : init_args, Module {}; struct init_mod : init_args, Module {};
init_mod init_new(); init_mod init_new();
void init_create(init_args arg); void init_create(init_args arg);
void init_dispatch(std::string arguments); void init_dispatch(std::string arguments);
#endif #endif

38127
vendor/json.hpp vendored

File diff suppressed because it is too large Load Diff