Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lsproule committed Oct 25, 2023
1 parent 05d140f commit da7e188
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/Command/CommandAdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
47 changes: 0 additions & 47 deletions src/Command/CommandGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,52 +50,5 @@ namespace Command {

return true;
};
bool writePackageToml(std::shared_ptr<Context> 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
34 changes: 26 additions & 8 deletions src/Generators/ConfigTomlGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,12 @@ namespace Generators::ConfigToml {
}



bool writeConfig(std::shared_ptr<Command::Context> &ctx){
bool writeConfig(std::shared_ptr<Command::Context> &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{
Expand All @@ -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;
}



}

0 comments on commit da7e188

Please sign in to comment.