Add init module.
- Update .clang-format's IndentWidth - Apply new .clang-format. - Add init module.
This commit is contained in:
parent
13b59e6bef
commit
b1008403bb
|
@ -22,7 +22,7 @@ ColumnLimit: '80'
|
|||
CompactNamespaces: 'true'
|
||||
IncludeBlocks: Preserve
|
||||
IndentWidth: '2'
|
||||
SpaceBeforeParens: Never
|
||||
SpaceBeforeParens: 'ControlStatements'
|
||||
SpaceBeforeRangeBasedForLoopColon: 'false'
|
||||
SpaceInEmptyParentheses: 'false'
|
||||
SpacesBeforeTrailingComments: '1'
|
||||
|
|
|
@ -51,9 +51,8 @@ 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) {
|
||||
} catch (std::exception& ex) {
|
||||
std::cout << "Failed writing database to: " << dest << std::endl;
|
||||
std::cout << "Error: " << ex.what() << std::endl;
|
||||
}
|
||||
|
@ -65,7 +64,7 @@ void loadDB(DB& db, const std::string& src) {
|
|||
json j;
|
||||
f >> j;
|
||||
db = j;
|
||||
} catch(const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cout << "Failed loading database from: " << src << std::endl;
|
||||
std::cout << "Error: " << ex.what() << std::endl;
|
||||
}
|
||||
|
|
31
src/main.cpp
31
src/main.cpp
|
@ -8,10 +8,16 @@
|
|||
#include "modules/init.h"
|
||||
|
||||
Module* get_Mod(std::string name) {
|
||||
if(true) {}
|
||||
if (name == "init") {
|
||||
return init_new();
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
void dispatch_Mod(Module* mod, std::string args){};
|
||||
void dispatch_Mod(std::string mod, std::string args) {
|
||||
if (mod == "init") {
|
||||
init_dispatch(args);
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
using namespace boost::program_options;
|
||||
|
@ -36,35 +42,34 @@ int main(int argc, const char* argv[]) {
|
|||
vm);
|
||||
notify(vm);
|
||||
|
||||
if(vm.count("help")) {
|
||||
if (vm.count("help")) {
|
||||
std::cout << general << "\n";
|
||||
exit(0);
|
||||
} else if(vm.count("help-module")) {
|
||||
} else if (vm.count("help-module")) {
|
||||
auto name = vm["help-module"].as<string>();
|
||||
auto module = get_Mod(name);
|
||||
if(!module) {
|
||||
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) {
|
||||
} else if (vm.count("module")) {
|
||||
auto name = vm["module"].as<string>();
|
||||
if (!get_Mod(name)) {
|
||||
std::cout << "Module not found.\n";
|
||||
exit(1);
|
||||
}
|
||||
if(vm.count("module-args")) {
|
||||
if (vm.count("module-args")) {
|
||||
auto args = vm["module-args"].as<string>();
|
||||
dispatch_Mod(module, args);
|
||||
dispatch_Mod(name, args);
|
||||
} else
|
||||
dispatch_Mod(module, "");
|
||||
dispatch_Mod(name, "");
|
||||
} else {
|
||||
std::cout << general << "\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
} catch(const error& ex) { cerr << ex.what() << '\n'; }
|
||||
} catch (const error& ex) { cerr << ex.what() << '\n'; }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,14 +24,14 @@ void init_create(init_args arg) {
|
|||
writeDB(db, ".db");
|
||||
}
|
||||
|
||||
void init_dispatch() {
|
||||
void init_dispatch(std::string arguments) {
|
||||
init_args arg;
|
||||
init_create(arg);
|
||||
}
|
||||
|
||||
init_mod init_new() {
|
||||
init_mod mod;
|
||||
mod.name = "Init";
|
||||
mod.desc = "Creates skidjular directory in $(pwd)";
|
||||
init_mod* init_new() {
|
||||
init_mod* mod = new init_mod{};
|
||||
mod->name = "Init";
|
||||
mod->desc = "Creates skidjular directory in $(pwd)";
|
||||
return mod;
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
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);
|
||||
init_mod* init_new();
|
||||
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