Run pre-commit on files
This commit is contained in:
parent
5eae19af68
commit
63ad0d6ba1
|
@ -5,7 +5,7 @@ on: [push]
|
|||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: build
|
||||
|
|
|
@ -5,7 +5,7 @@ on: [push]
|
|||
jobs:
|
||||
build:
|
||||
runs-on: macOS-latest
|
||||
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: build
|
||||
|
|
|
@ -33,5 +33,5 @@ file(GLOB_RECURSE skidjular_srcs "src/*.cpp")
|
|||
include_directories("src/")
|
||||
include_directories("vendor/")
|
||||
|
||||
add_executable(skidjular ${skidjular_hdrs} ${skidjular_srcs})
|
||||
add_executable(skidjular ${skidjular_hdrs} ${skidjular_srcs})
|
||||
target_link_libraries(skidjular ${CONAN_LIBS})
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
## How to Contribute
|
||||
|
||||
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
|
||||
|
||||
|
@ -11,4 +11,4 @@ When submitting a pull request:
|
|||
|
||||
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.
|
||||
3. Open a pull request on GitHub.
|
||||
3. Open a pull request on GitHub.
|
||||
|
|
109
src/data.cpp
109
src/data.cpp
|
@ -1,81 +1,72 @@
|
|||
#include "data.h"
|
||||
|
||||
void to_json(json& j, const Date& date) {
|
||||
j = json{
|
||||
{"day", date.day},
|
||||
{"month", date.day},
|
||||
{"year", date.year}
|
||||
};
|
||||
j = json{{"day", date.day}, {"month", date.day}, {"year", date.year}};
|
||||
}
|
||||
void from_json(const json& j, Date& date) {
|
||||
j.at("day").get_to(date.day);
|
||||
j.at("month").get_to(date.month);
|
||||
j.at("year").get_to(date.year);
|
||||
j.at("day").get_to(date.day);
|
||||
j.at("month").get_to(date.month);
|
||||
j.at("year").get_to(date.year);
|
||||
}
|
||||
void to_json(json& j, const Project& proj) {
|
||||
j = json{
|
||||
{"name", proj.name},
|
||||
{"desc", proj.desc},
|
||||
{"uuid", proj.uuid},
|
||||
{"pri", proj.pri},
|
||||
{"creationDate", proj.creationDate},
|
||||
{"doneDate", proj.doneDate},
|
||||
{"isDone", proj.isDone}
|
||||
};
|
||||
j = json{{"name", proj.name},
|
||||
{"desc", proj.desc},
|
||||
{"uuid", proj.uuid},
|
||||
{"pri", proj.pri},
|
||||
{"creationDate", proj.creationDate},
|
||||
{"doneDate", proj.doneDate},
|
||||
{"isDone", proj.isDone}};
|
||||
}
|
||||
void from_json(const json& j, Project& proj) {
|
||||
j.at("name").get_to(proj.name);
|
||||
j.at("desc").get_to(proj.desc);
|
||||
j.at("uuid").get_to(proj.uuid);
|
||||
j.at("pri").get_to(proj.pri);
|
||||
j.at("creationDate").get_to(proj.creationDate);
|
||||
j.at("doneDate").get_to(proj.doneDate);
|
||||
j.at("isDone").get_to(proj.isDone);
|
||||
j.at("name").get_to(proj.name);
|
||||
j.at("desc").get_to(proj.desc);
|
||||
j.at("uuid").get_to(proj.uuid);
|
||||
j.at("pri").get_to(proj.pri);
|
||||
j.at("creationDate").get_to(proj.creationDate);
|
||||
j.at("doneDate").get_to(proj.doneDate);
|
||||
j.at("isDone").get_to(proj.isDone);
|
||||
}
|
||||
void to_json(json& j, const Skid& skid) {
|
||||
j = json{
|
||||
{"projects", *skid.projects},
|
||||
{"creationDate", skid.creationDate},
|
||||
};
|
||||
j = json{
|
||||
{"projects", *skid.projects},
|
||||
{"creationDate", skid.creationDate},
|
||||
};
|
||||
}
|
||||
void from_json(const json& j, Skid& skid) {
|
||||
j.at("projects").get_to(*skid.projects);
|
||||
j.at("creationDate").get_to(skid.creationDate);
|
||||
j.at("projects").get_to(*skid.projects);
|
||||
j.at("creationDate").get_to(skid.creationDate);
|
||||
}
|
||||
void to_json(json& j, const DB& db) {
|
||||
j = json{
|
||||
{"projects", *db.projects},
|
||||
{"creationDate", db.creationDate},
|
||||
{"lastAccessTime", db.lastAccessTime}
|
||||
};
|
||||
j = json{{"projects", *db.projects},
|
||||
{"creationDate", db.creationDate},
|
||||
{"lastAccessTime", db.lastAccessTime}};
|
||||
}
|
||||
void from_json(const json& j, DB& db) {
|
||||
j.at("projects").get_to(*db.projects);
|
||||
j.at("creationDate").get_to(db.creationDate);
|
||||
j.at("lastAccessTime").get_to(db.lastAccessTime);
|
||||
j.at("projects").get_to(*db.projects);
|
||||
j.at("creationDate").get_to(db.creationDate);
|
||||
j.at("lastAccessTime").get_to(db.lastAccessTime);
|
||||
}
|
||||
|
||||
|
||||
void writeDB(DB db, const std::string &dest) {
|
||||
try {
|
||||
std::ofstream f(dest);
|
||||
json j = db;
|
||||
std::cout << "hello" << std::endl;
|
||||
f << j;
|
||||
} catch (std::exception &ex) {
|
||||
std::cout << "Failed writing database to: " << dest << std::endl;
|
||||
std::cout << "Error: " << ex.what() << std::endl;
|
||||
}
|
||||
void writeDB(DB db, const std::string& dest) {
|
||||
try {
|
||||
std::ofstream f(dest);
|
||||
json j = db;
|
||||
std::cout << "hello" << std::endl;
|
||||
f << j;
|
||||
} catch(std::exception& ex) {
|
||||
std::cout << "Failed writing database to: " << dest << std::endl;
|
||||
std::cout << "Error: " << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void loadDB(DB &db, const std::string &src) {
|
||||
try {
|
||||
std::ifstream f(src);
|
||||
json j;
|
||||
f >> j;
|
||||
db = j;
|
||||
} catch (const std::exception& ex) {
|
||||
std::cout << "Failed loading database from: " << src << std::endl;
|
||||
std::cout << "Error: " << ex.what() << std::endl;
|
||||
}
|
||||
void loadDB(DB& db, const std::string& src) {
|
||||
try {
|
||||
std::ifstream f(src);
|
||||
json j;
|
||||
f >> j;
|
||||
db = j;
|
||||
} catch(const std::exception& ex) {
|
||||
std::cout << "Failed loading database from: " << src << std::endl;
|
||||
std::cout << "Error: " << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
52
src/data.h
52
src/data.h
|
@ -10,31 +10,31 @@
|
|||
#include "json.hpp"
|
||||
using nlohmann::json;
|
||||
|
||||
#define LOC_DB = ".db"
|
||||
#define LOC_DB = ".db"
|
||||
#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 ///////////////////
|
||||
|
||||
struct Date {
|
||||
int day = 0;
|
||||
int month = 0; // 0-11
|
||||
int year = 0; // + 1900 for currentyear
|
||||
int day = 0;
|
||||
int month = 0; // 0-11
|
||||
int year = 0; // + 1900 for currentyear
|
||||
};
|
||||
|
||||
struct Project {
|
||||
std::string name = "";
|
||||
std::string desc = "";
|
||||
std::string uuid;
|
||||
int pri = 0;
|
||||
Date creationDate;
|
||||
Date doneDate;
|
||||
bool isDone = false;
|
||||
std::string name = "";
|
||||
std::string desc = "";
|
||||
std::string uuid;
|
||||
int pri = 0;
|
||||
Date creationDate;
|
||||
Date doneDate;
|
||||
bool isDone = false;
|
||||
};
|
||||
|
||||
struct Skid {
|
||||
std::vector<Project> *projects = {};
|
||||
Date creationDate;
|
||||
std::vector<Project>* projects = {};
|
||||
Date creationDate;
|
||||
};
|
||||
|
||||
/////////////// END OF DATA CONTAINING STRUCTURES ////////////
|
||||
|
@ -44,32 +44,32 @@ struct Skid {
|
|||
enum EventType { Access = 0, Creation = 1, Modification = 2, None = -1 };
|
||||
|
||||
struct Event {
|
||||
int id = -1;
|
||||
EventType type = EventType::None;
|
||||
std::string mesg = "";
|
||||
int id = -1;
|
||||
EventType type = EventType::None;
|
||||
std::string mesg = "";
|
||||
};
|
||||
|
||||
struct EventLog {
|
||||
std::vector<Event> *events;
|
||||
std::string sha512 = "";
|
||||
std::vector<Event>* events;
|
||||
std::string sha512 = "";
|
||||
};
|
||||
|
||||
/////////////// EVENT END OF HISTORY SYSTEM STRUCTURES /////////////
|
||||
|
||||
// Main Database that represents the skidjular directory.
|
||||
struct DB {
|
||||
std::map<std::string, Project> *projects;
|
||||
std::vector<Skid> skids;
|
||||
EventLog log;
|
||||
std::map<std::string, Project>* projects;
|
||||
std::vector<Skid> skids;
|
||||
EventLog log;
|
||||
|
||||
Date creationDate;
|
||||
Date lastAccessTime;
|
||||
Date creationDate;
|
||||
Date lastAccessTime;
|
||||
};
|
||||
|
||||
////////////// Utilities for the Database structure ////////////////
|
||||
|
||||
void writeDB(DB db, const std::string &dest);
|
||||
void loadDB(DB &db, const std::string &src);
|
||||
void writeDB(DB db, const std::string& dest);
|
||||
void loadDB(DB& db, const std::string& src);
|
||||
|
||||
////////////// End Utilities for the Database structure ////////////
|
||||
|
||||
|
|
83
src/main.cpp
83
src/main.cpp
|
@ -7,62 +7,63 @@
|
|||
#include "module.h"
|
||||
#include "modules/init.h"
|
||||
|
||||
Module* get_Mod(std::string name) {return nullptr;};
|
||||
void dispatch_Mod(Module* mod, std::string args) {};
|
||||
Module* get_Mod(std::string name) {
|
||||
return nullptr;
|
||||
};
|
||||
void dispatch_Mod(Module* mod, std::string args){};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
using namespace boost::program_options;
|
||||
using namespace std;
|
||||
using namespace boost::program_options;
|
||||
using namespace std;
|
||||
|
||||
try {
|
||||
try {
|
||||
options_description general("General Options");
|
||||
general.add_options()("help", "Help Message")(
|
||||
"help-module", value<string>(), "Module for help message")(
|
||||
"module", value<string>(), "Module to execute")(
|
||||
"module-args", value<string>(), "Arguments to use");
|
||||
"help-module", value<string>(), "Module for help message")(
|
||||
"module", value<string>(), "Module to execute")(
|
||||
"module-args", value<string>(), "Arguments to use");
|
||||
positional_options_description general_positional;
|
||||
general_positional.add("module", 1);
|
||||
general_positional.add("module-args", 10);
|
||||
|
||||
variables_map vm;
|
||||
store(command_line_parser(argc, argv)
|
||||
.options(general)
|
||||
.allow_unregistered()
|
||||
.positional(general_positional)
|
||||
.run(),
|
||||
vm);
|
||||
.options(general)
|
||||
.allow_unregistered()
|
||||
.positional(general_positional)
|
||||
.run(),
|
||||
vm);
|
||||
notify(vm);
|
||||
|
||||
if (vm.count("help")) {
|
||||
std::cout << general << "\n";
|
||||
exit(0);
|
||||
} else if (vm.count("help-module")) {
|
||||
auto name = vm["help-module"].as<string>();
|
||||
auto module = get_Mod(name);
|
||||
if (!module) {
|
||||
std::cout << "Module not found.\n";
|
||||
exit(1);
|
||||
}
|
||||
std::cout << module->desc << "\n";
|
||||
} else if (vm.count("module")) {
|
||||
auto name = vm["module"].as<string>();
|
||||
auto module = get_Mod(name);
|
||||
if (!module) {
|
||||
std::cout << "Module not found.\n";
|
||||
exit(1);
|
||||
}
|
||||
if (vm.count("module-args")) {
|
||||
auto args = vm["module-args"].as<string>();
|
||||
dispatch_Mod(module, args);
|
||||
} else dispatch_Mod(module, "");
|
||||
if(vm.count("help")) {
|
||||
std::cout << general << "\n";
|
||||
exit(0);
|
||||
} else if(vm.count("help-module")) {
|
||||
auto name = vm["help-module"].as<string>();
|
||||
auto module = get_Mod(name);
|
||||
if(!module) {
|
||||
std::cout << "Module not found.\n";
|
||||
exit(1);
|
||||
}
|
||||
std::cout << module->desc << "\n";
|
||||
} else if(vm.count("module")) {
|
||||
auto name = vm["module"].as<string>();
|
||||
auto module = get_Mod(name);
|
||||
if(!module) {
|
||||
std::cout << "Module not found.\n";
|
||||
exit(1);
|
||||
}
|
||||
if(vm.count("module-args")) {
|
||||
auto args = vm["module-args"].as<string>();
|
||||
dispatch_Mod(module, args);
|
||||
} else
|
||||
dispatch_Mod(module, "");
|
||||
} else {
|
||||
std::cout << general << "\n";
|
||||
exit(0);
|
||||
std::cout << general << "\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
} catch (const error& ex) {
|
||||
cerr << ex.what() << '\n';
|
||||
}
|
||||
} catch(const error& ex) { cerr << ex.what() << '\n'; }
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
#include <map>
|
||||
#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)>;
|
||||
|
||||
struct Module {
|
||||
std::string name;
|
||||
std::string desc;
|
||||
std::map<std::string, ModuleFn> funcs;
|
||||
std::string name;
|
||||
std::string desc;
|
||||
std::map<std::string, ModuleFn> funcs;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,35 +3,35 @@
|
|||
#include "../data.h"
|
||||
|
||||
void init_create(init_args arg) {
|
||||
std::cout << "Creating database in current directory." << std::endl;
|
||||
DB db;
|
||||
time_t t = time(0);
|
||||
struct tm *currentTime = localtime(&t);
|
||||
std::cout << "Creating database in current directory." << std::endl;
|
||||
DB db;
|
||||
time_t t = time(0);
|
||||
struct tm* currentTime = localtime(&t);
|
||||
|
||||
db.creationDate.day = currentTime->tm_mday;
|
||||
db.creationDate.month = currentTime->tm_mon;
|
||||
db.creationDate.year = currentTime->tm_year;
|
||||
db.lastAccessTime.day = currentTime->tm_mday;
|
||||
db.lastAccessTime.month = currentTime->tm_mon;
|
||||
db.lastAccessTime.year = currentTime->tm_year;
|
||||
db.creationDate.day = currentTime->tm_mday;
|
||||
db.creationDate.month = currentTime->tm_mon;
|
||||
db.creationDate.year = currentTime->tm_year;
|
||||
db.lastAccessTime.day = currentTime->tm_mday;
|
||||
db.lastAccessTime.month = currentTime->tm_mon;
|
||||
db.lastAccessTime.year = currentTime->tm_year;
|
||||
|
||||
// Mandatory stuff to stop segmantion fault due to
|
||||
// pointers unintialized.
|
||||
db.projects = new std::map<std::string, Project>();
|
||||
db.log.events = new std::vector<Event>();
|
||||
// Mandatory stuff to stop segmantion fault due to
|
||||
// pointers unintialized.
|
||||
db.projects = new std::map<std::string, Project>();
|
||||
db.log.events = new std::vector<Event>();
|
||||
|
||||
// TODO: Add event logging
|
||||
writeDB(db, ".db");
|
||||
// TODO: Add event logging
|
||||
writeDB(db, ".db");
|
||||
}
|
||||
|
||||
void init_dispatch() {
|
||||
init_args arg;
|
||||
init_create(arg);
|
||||
init_args arg;
|
||||
init_create(arg);
|
||||
}
|
||||
|
||||
init_mod init_new() {
|
||||
init_mod mod;
|
||||
mod.name = "Init";
|
||||
mod.desc = "Creates skidjular directory in $(pwd)";
|
||||
return mod;
|
||||
init_mod mod;
|
||||
mod.name = "Init";
|
||||
mod.desc = "Creates skidjular directory in $(pwd)";
|
||||
return mod;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ struct init_args {};
|
|||
struct init_mod : init_args, Module {};
|
||||
|
||||
init_mod init_new();
|
||||
void init_create(init_args arg);
|
||||
void init_dispatch(std::string arguments);
|
||||
void init_create(init_args arg);
|
||||
void init_dispatch(std::string arguments);
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue