From 78330be3f1b6a1346052204430582d101728a414 Mon Sep 17 00:00:00 2001 From: "lucas.sproule" Date: Fri, 3 Nov 2023 16:49:27 -0400 Subject: [PATCH] fuck toml++ --- README.md | 2 +- src/Command/Command.hpp | 10 +-- src/Command/CommandAdd.cpp | 4 +- src/Command/CommandFTP.cpp | 2 +- src/Command/CommandInit.cpp | 65 +++++++++++-------- ...lGenerator.cpp => ConfigJsonGenerator.cpp} | 2 +- src/Generators/Generators.hpp | 18 ++--- src/Generators/Validators/BuildDir.cpp | 18 ++--- src/Generators/Validators/CMakeVersion.cpp | 2 +- src/Generators/Validators/Compiler.cpp | 2 +- src/Generators/Validators/IncludeDir.cpp | 2 +- src/Generators/Validators/Language.cpp | 2 +- src/Generators/Validators/LanguageVersion.cpp | 2 +- src/Generators/Validators/ProjectName.cpp | 2 +- src/Generators/Validators/ProjectVersion.cpp | 14 ++-- src/Generators/Validators/SourceDir.cpp | 2 +- src/Test/Test.hpp | 2 +- src/Test/TestGenerators.cpp | 2 +- 18 files changed, 81 insertions(+), 72 deletions(-) rename src/Generators/{ConfigTomlGenerator.cpp => ConfigJsonGenerator.cpp} (98%) diff --git a/README.md b/README.md index 771e28e..ad4b39a 100644 --- a/README.md +++ b/README.md @@ -70,4 +70,4 @@ cmake-generator is a command line utility used to expedite building modern c/c++ - [x] Simple dependency management - [ ] Multi platform builds - [ ] Existing cmake project migration -- [ ] Extensible toml configuration +- [ ] Extensible json configuration diff --git a/src/Command/Command.hpp b/src/Command/Command.hpp index 861e3ca..8c7cb56 100644 --- a/src/Command/Command.hpp +++ b/src/Command/Command.hpp @@ -35,7 +35,7 @@ namespace Command { } // opening the file if (file) { - std::cout << "file config.toml exists" << std::endl; + std::cout << "file config.json exists" << std::endl; std::cout << "do you want to overwrite it?[y/n]:"; std::string input; std::getline(std::cin, input); @@ -180,12 +180,12 @@ namespace Command { /* - * Loads the config.toml file into the project context + * Loads the config.json file into the project context * @param a blank project context * @return bool -> finished successfully */ [[deprecated("Old function, Command::Interface ")]] - bool loadPackageToml(std::shared_ptr ctx); + bool loadPackageJson(std::shared_ptr ctx); /* * Initializes the project * Prompts the user for information about the project @@ -223,7 +223,7 @@ namespace Command { [[deprecated("Old function, Command::Interface ")]] bool help(); /* - * adds a dependency to the config.toml + * adds a dependency to the config.json * @returns bool -> finished successfully */ [[deprecated("Old function, Command::Interface ")]] @@ -244,7 +244,7 @@ namespace Command { std::string downloadIndex(); /* - * adds dependency to toml and regenerates the CMakeLists.txt + * adds dependency to json and regenerates the CMakeLists.txt * @returns bool -> finished successfully */ [[deprecated("Old function, Command::Interface ")]] diff --git a/src/Command/CommandAdd.cpp b/src/Command/CommandAdd.cpp index c386988..33636da 100644 --- a/src/Command/CommandAdd.cpp +++ b/src/Command/CommandAdd.cpp @@ -116,7 +116,7 @@ namespace Command { return false; } - std::cout << "Adding dependency to config.toml" << std::endl; + std::cout << "Adding dependency to config.json" << std::endl; ctx->dependencies.push_back({ .name = searchResults[index].name, @@ -128,7 +128,7 @@ namespace Command { : searchResults[index].target_link }); - std::cout << "Writing config.toml" << std::endl; + std::cout << "Writing config.json" << std::endl; Generators::ConfigJson::writeConfig(ctx); Generators::CMakeList::create(ctx); diff --git a/src/Command/CommandFTP.cpp b/src/Command/CommandFTP.cpp index d5b6c26..d6a300e 100644 --- a/src/Command/CommandFTP.cpp +++ b/src/Command/CommandFTP.cpp @@ -5,7 +5,7 @@ namespace Command{ bool Interface::ftp() { bool test = this->LoadPackageJson(); if(!test) { - std::cout << "Error: Could not load config.toml" << std::endl; + std::cout << "Error: Could not load config.json" << std::endl; return false; } #ifdef DEBUG diff --git a/src/Command/CommandInit.cpp b/src/Command/CommandInit.cpp index afb9f66..68ecbce 100644 --- a/src/Command/CommandInit.cpp +++ b/src/Command/CommandInit.cpp @@ -12,7 +12,7 @@ namespace Command { -bool createToml(std::shared_ptr ctx) { +bool createJson(std::shared_ptr ctx) { //Lucas did it again std::shared_ptrconfig_json = std::make_shared(); Generators::ConfigJson::readUserInput(ctx, config_json); @@ -55,7 +55,7 @@ bool createHelloWorldC(std::shared_ptr ctx) { } bool createProject(Interface *inter){ - createToml(inter->ctx); + createJson(inter->ctx); inter->LoadPackageJson(); Generators::CMakeList::create(inter->ctx); if(inter->ctx->lang == "cpp"){ @@ -67,36 +67,45 @@ bool createProject(Interface *inter){ } -bool defaultTomlCpp(std::shared_ptr ctx) { +bool defaultJsonCpp(std::shared_ptr ctx) { + using nlohmann::json; std::string language = ctx->args->operator[]("language").as(); std::string name = ctx->args->operator[]("name").as(); - toml::array authors = toml::array{}; - toml::table table = toml::table{ - {"project", - toml::table{ - {"cmake_version", ctx->cmake_version}, - {"include_dir", ctx->include_dir}, - {"project_version", ctx->project_version}, - {"compiler", ctx->compiler}, - {"project_name", ctx->project_name}, - {"authors", authors}, - {"src_dir", ctx->src_dir}, - {"build_dir", ctx->build_dir}, - {"lang", ctx->lang}, - {"lang_version", ctx->lang_version}, - }}, - }; - - - std::cout << "📄 New Toml File: \n"; - std::cout << table << '\n'; + json j; + j["cmake_version"] = ctx->cmake_version; + j["project_version"] = ctx->project_version; + j["lang"] = ctx->lang; + j["lang_version"] = ctx->lang_version; + j["compiler"] = ctx->compiler; + j["src_dir"] = ctx->src_dir; + j["build_dir"] = ctx->build_dir; + j["include_dir"] = ctx->include_dir; + j["project_name"] = ctx->project_name; + j["authors"] = ctx->authors; + j["project_path"] = ctx->project_path; + j["project_type"] = ctx->project_type; + j["project_description"] = ctx->project_description; + j["flags"] = ctx->flags; + std::vector deps; + for (auto &dep : ctx->dependencies) { + json dep_json; + dep_json["name"] = dep.name; + dep_json["url"] = dep.url; + dep_json["version"] = dep.version; + dep_json["target_link"] = dep.target_link; + deps.push_back(dep_json); + } + j["dependencies"] = deps; + + std::cout << "📄 New json File: \n"; + std::cout << j << '\n'; std::ofstream file; - std::string file_name = "config.toml"; + std::string file_name = "config.json"; file.open(ctx->project_path / file_name); - file << table; + file << j; file << '\n'; file.close(); return false; @@ -124,17 +133,17 @@ bool Interface::init() { } std::cout << "project path" << ctx->project_path << ENDL; - std::cout << "config.toml path" << ctx->project_path / file_name << ENDL; + std::cout << "config.json path" << ctx->project_path / file_name << ENDL; std::string current_path = ctx->project_path.string(); if (args->operator[]("skip-init").as()) { std::string language = args->operator[]("language").as(); if (language == "cpp" || language == "c++"){ - defaultTomlCpp(ctx); + defaultJsonCpp(ctx); } else if (language == "c") { - //defaultTomlC(ctx, args); + //defaultJsonC(ctx, args); std::cout << "C is not supported yet" << ENDL; exit(-1); } diff --git a/src/Generators/ConfigTomlGenerator.cpp b/src/Generators/ConfigJsonGenerator.cpp similarity index 98% rename from src/Generators/ConfigTomlGenerator.cpp rename to src/Generators/ConfigJsonGenerator.cpp index 4e550b4..93212a0 100644 --- a/src/Generators/ConfigTomlGenerator.cpp +++ b/src/Generators/ConfigJsonGenerator.cpp @@ -71,4 +71,4 @@ namespace Generators::ConfigJson{ return true; } -} // namespace Generators::ConfigToml +} // namespace Generators::ConfigJson diff --git a/src/Generators/Generators.hpp b/src/Generators/Generators.hpp index 018728e..072333f 100644 --- a/src/Generators/Generators.hpp +++ b/src/Generators/Generators.hpp @@ -61,7 +61,7 @@ namespace Generators{ * Validate cmakeVersion * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the cmake version is valid */ bool validateCmakeVersion(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json); @@ -70,7 +70,7 @@ namespace Generators{ * Validates the project name * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the project name is valid */ bool validateProjectName(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json); @@ -79,7 +79,7 @@ namespace Generators{ * Validates the project version * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the project version is valid */ bool validateProjectVersion(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json); @@ -88,7 +88,7 @@ namespace Generators{ * Validates the language version * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the language version is valid */ bool validateLanguageVersion(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json); @@ -97,7 +97,7 @@ namespace Generators{ * Validates the compiler * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the language is valid */ bool validateCompiler(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json); @@ -106,7 +106,7 @@ namespace Generators{ * Validates the source directory * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the source directory is valid */ bool validateSourceDir(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json); @@ -115,7 +115,7 @@ namespace Generators{ * Validates the build directory * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the build directory is valid */ bool validateBuildDir(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json); @@ -123,7 +123,7 @@ namespace Generators{ /* * Reads the data from the user * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the data is valid */ bool validateIncludeDir(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json); @@ -133,7 +133,7 @@ namespace Generators{ * Validates the language * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the language is valid */ bool validateLang(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json); diff --git a/src/Generators/Validators/BuildDir.cpp b/src/Generators/Validators/BuildDir.cpp index 6844419..f2cad75 100644 --- a/src/Generators/Validators/BuildDir.cpp +++ b/src/Generators/Validators/BuildDir.cpp @@ -11,34 +11,34 @@ namespace Generators::ConfigJson{ * Validates the build directory * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_toml: the config toml context + * @param config_json: the config json context * @return: true if the build directory is valid */ - bool validateBuildDir(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_toml) { + bool validateBuildDir(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json) { std::cout << prefix; #ifndef TEST - std::getline(std::cin, config_toml->build_dir); + std::getline(std::cin, config_json->build_dir); #endif //If the build directory is empty we're gonna set it - if(config_toml->build_dir == "") { + if(config_json->build_dir == "") { goto end; } - if (config_toml->build_dir.size() > 255) { + if (config_json->build_dir.size() > 255) { return false; } - if (config_toml->build_dir == "build") { + if (config_json->build_dir == "build") { goto end; } //check if the build directory is valid - if (std::regex_match(config_toml->build_dir, std::regex("^[a-zA-Z0-9_-]+$"))) { + if (std::regex_match(config_json->build_dir, std::regex("^[a-zA-Z0-9_-]+$"))) { goto end; } - if (sizeof(config_toml->build_dir) > 255) { + if (sizeof(config_json->build_dir) > 255) { goto end; } return false; end: - ctx->build_dir = config_toml->build_dir == "" ? ctx->build_dir : config_toml->build_dir; + ctx->build_dir = config_json->build_dir == "" ? ctx->build_dir : config_json->build_dir; return true; } diff --git a/src/Generators/Validators/CMakeVersion.cpp b/src/Generators/Validators/CMakeVersion.cpp index 2bc1eb5..7cf18d5 100644 --- a/src/Generators/Validators/CMakeVersion.cpp +++ b/src/Generators/Validators/CMakeVersion.cpp @@ -11,7 +11,7 @@ namespace Generators::ConfigJson{ * Validates the cmake version * @param prefix: the prefix of the message @param ctx: the context of the * command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the version is valid */ bool validateCmakeVersion(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json) { diff --git a/src/Generators/Validators/Compiler.cpp b/src/Generators/Validators/Compiler.cpp index 6cdcc32..33b0891 100644 --- a/src/Generators/Validators/Compiler.cpp +++ b/src/Generators/Validators/Compiler.cpp @@ -12,7 +12,7 @@ namespace Generators::ConfigJson{ * Validates the compiler * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the language is valid */ bool validateCompiler(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json) { diff --git a/src/Generators/Validators/IncludeDir.cpp b/src/Generators/Validators/IncludeDir.cpp index a8213d4..76fd818 100644 --- a/src/Generators/Validators/IncludeDir.cpp +++ b/src/Generators/Validators/IncludeDir.cpp @@ -11,7 +11,7 @@ namespace Generators::ConfigJson{ /* * Reads the data from the user * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the data is valid */ bool validateIncludeDir(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json) { diff --git a/src/Generators/Validators/Language.cpp b/src/Generators/Validators/Language.cpp index 6847864..c2e02ac 100644 --- a/src/Generators/Validators/Language.cpp +++ b/src/Generators/Validators/Language.cpp @@ -11,7 +11,7 @@ namespace Generators::ConfigJson{ * Validates the language * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the language is valid */ bool validateLang(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json) { diff --git a/src/Generators/Validators/LanguageVersion.cpp b/src/Generators/Validators/LanguageVersion.cpp index 5e6ce12..5249b94 100644 --- a/src/Generators/Validators/LanguageVersion.cpp +++ b/src/Generators/Validators/LanguageVersion.cpp @@ -11,7 +11,7 @@ namespace Generators::ConfigJson{ * Validates the language version * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the language version is valid */ bool validateLanguageVersion(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json) { diff --git a/src/Generators/Validators/ProjectName.cpp b/src/Generators/Validators/ProjectName.cpp index 53b1324..a546296 100644 --- a/src/Generators/Validators/ProjectName.cpp +++ b/src/Generators/Validators/ProjectName.cpp @@ -11,7 +11,7 @@ namespace Generators::ConfigJson{ * Validates the project name * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the project name is valid */ bool validateProjectName(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json) { diff --git a/src/Generators/Validators/ProjectVersion.cpp b/src/Generators/Validators/ProjectVersion.cpp index c3fffb8..5a33dd8 100644 --- a/src/Generators/Validators/ProjectVersion.cpp +++ b/src/Generators/Validators/ProjectVersion.cpp @@ -12,29 +12,29 @@ namespace Generators::ConfigJson{ * Validates the project version * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_toml: the config toml context + * @param config_json: the config json context * @return: true if the project version is valid */ - bool validateProjectVersion(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_toml) { + bool validateProjectVersion(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json) { std::cout << prefix; #ifndef TEST - std::getline(std::cin, config_toml->project_version); + std::getline(std::cin, config_json->project_version); #endif - if(config_toml->project_version == "") { + if(config_json->project_version == "") { goto end; } //Checking if the version is x.x.x - if(std::regex_match(config_toml->project_version, std::regex("^[0-9]+\\.[0-9]+\\.[0-9]+$"))) { + if(std::regex_match(config_json->project_version, std::regex("^[0-9]+\\.[0-9]+\\.[0-9]+$"))) { goto end; } //Checking if the version is x.x - if(std::regex_match(config_toml->project_version, std::regex("^[0-9]+\\.[0-9]+$"))) { + if(std::regex_match(config_json->project_version, std::regex("^[0-9]+\\.[0-9]+$"))) { goto end; } return false; //If the version is empty we're gonna set it end: - ctx->project_version = config_toml->project_version == "" ? ctx->project_version : config_toml->project_version; + ctx->project_version = config_json->project_version == "" ? ctx->project_version : config_json->project_version; return true; diff --git a/src/Generators/Validators/SourceDir.cpp b/src/Generators/Validators/SourceDir.cpp index 0ce9381..4e48780 100644 --- a/src/Generators/Validators/SourceDir.cpp +++ b/src/Generators/Validators/SourceDir.cpp @@ -12,7 +12,7 @@ namespace Generators::ConfigJson{ * Validates the source directory * @param prefix: the prefix of the message * @param ctx: the context of the command - * @param config_json: the config toml context + * @param config_json: the config json context * @return: true if the source directory is valid */ bool validateSourceDir(std::string prefix, std::shared_ptr ctx, std::shared_ptr config_json) { diff --git a/src/Test/Test.hpp b/src/Test/Test.hpp index 99b9205..bbdc877 100644 --- a/src/Test/Test.hpp +++ b/src/Test/Test.hpp @@ -26,7 +26,7 @@ namespace Tests::Generators{ bool testBuildDir(); bool testIncludeDir(); } - namespace TomlConfig{ + namespace JsonConfig{ } } namespace Tests::Utils { diff --git a/src/Test/TestGenerators.cpp b/src/Test/TestGenerators.cpp index 5344b73..f1b66ea 100644 --- a/src/Test/TestGenerators.cpp +++ b/src/Test/TestGenerators.cpp @@ -298,7 +298,7 @@ namespace Test::Generators { REQUIRE(CMakeLists::testIncludeDir()); }; }; - namespace TomlConfig { + namespace JsonConfig{ }; }