diff --git a/src/Command/CommandAdd.cpp b/src/Command/CommandAdd.cpp index 839c14b..ba3e8f1 100644 --- a/src/Command/CommandAdd.cpp +++ b/src/Command/CommandAdd.cpp @@ -34,7 +34,7 @@ namespace Command { ctx->dependencies.push_back(dependency_new); } std::cout << ctx->dependencies.size() << std::endl; - Command::writePackageToml(ctx); + Generators::ConfigToml::writeConfig(ctx); Generators::CMakeList::create(ctx); return true; } diff --git a/src/Command/CommandGeneral.cpp b/src/Command/CommandGeneral.cpp index c03f956..0b0f4de 100644 --- a/src/Command/CommandGeneral.cpp +++ b/src/Command/CommandGeneral.cpp @@ -50,52 +50,5 @@ namespace Command { return true; }; - bool writePackageToml(std::shared_ptr ctx) { - toml::array authors = toml::array{}; - toml::array flags = toml::array{}; - for (auto &flag : ctx->flags) { - flags.push_back(flag); - } - 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}, - {"cflags", flags}, - }}, - }; - - toml::table deps_table = toml::table{{"dependencies", toml::table{}}}; - - for (Command::dependency &dep : ctx->dependencies) { - - toml::array deps_values = toml::array{}; - deps_values.push_back(dep.url); - deps_values.push_back(dep.version); - deps_table["dependencies"].as_table()->insert(dep.name, deps_values); - } - std::ofstream file; - std::string file_name = "config.toml"; -#ifdef DEBUG - file_name = "build/config.toml"; - std::cout << "Writing config.toml to " << ctx->project_path / file_name - << std::endl; -#endif - file.open(ctx->project_path / file_name); - file << table; - file << '\n'; - file << deps_table; - file << '\n'; - file.close(); - return true; - } } // namespace Command diff --git a/src/Generators/ConfigTomlGenerator.cpp b/src/Generators/ConfigTomlGenerator.cpp index a0a4413..7267d2d 100644 --- a/src/Generators/ConfigTomlGenerator.cpp +++ b/src/Generators/ConfigTomlGenerator.cpp @@ -267,9 +267,12 @@ namespace Generators::ConfigToml { } - - bool writeConfig(std::shared_ptr &ctx){ + bool writeConfig(std::shared_ptr &ctx) { toml::array authors = toml::array{}; + toml::array flags = toml::array{}; + for (auto &flag : ctx->flags) { + flags.push_back(flag); + } toml::table table = toml::table{ {"project", toml::table{ @@ -283,21 +286,36 @@ namespace Generators::ConfigToml { {"build_dir", ctx->build_dir}, {"lang", ctx->lang}, {"lang_version", ctx->lang_version}, + {"cflags", flags}, }}, }; - std::cout << "📄New Toml File: \n"; - std::cout << table << '\n'; + + toml::table deps_table = toml::table{{"dependencies", toml::table{}}}; + + for (Command::dependency &dep : ctx->dependencies) { + + toml::array deps_values = toml::array{}; + deps_values.push_back(dep.url); + deps_values.push_back(dep.version); + deps_table["dependencies"].as_table()->insert(dep.name, deps_values); + } + std::ofstream file; std::string file_name = "config.toml"; - #ifdef DEBUG - file_name ="build/config.toml"; - #endif - std::cout << table << '\n'; +#ifdef DEBUG + file_name = "build/config.toml"; + std::cout << "Writing config.toml to " << ctx->project_path / file_name + << std::endl; +#endif file.open(ctx->project_path / file_name); file << table; file << '\n'; + file << deps_table; + file << '\n'; file.close(); return true; } + + }