#include "yscan.h" #include "file.h" #include #include #include #include #include #include #include #include namespace fs = std::filesystem; using namespace std::string_literals; int yscan(int argc, char* argv[]) { try { std::string name {fs::current_path().stem().string()}; std::vector sources; std::vector test_sources; for (const auto& i: fs::directory_iterator(".")) { fs::path p{i.path().filename()}; if (is_compile_unit_source_by_extension(p)) { if (p.string().substr(0, 4) == "test") { test_sources.push_back(p.string()); } else { sources.push_back(p.string()); } } } std::sort(sources.begin(), sources.end()); std::sort(test_sources.begin(), test_sources.end()); std::string sources_string{std::accumulate(sources.begin(), sources.end(), std::string{}, [](const std::string& sum, const std::string& i){return sum + " " + i + "\n";})}; std::string test_sources_string{std::accumulate(test_sources.begin(), test_sources.end(), std::string{}, [](const std::string& sum, const std::string& i){return sum + " " + i + "\n";})}; if (!test_sources_string.empty()) { test_sources_string = fmt::format(R"( {} {} )", "test-"s + name, test_sources_string); } std::string contents {R"( {} {} {})"}; contents = fmt::format(contents, name, sources_string, test_sources_string); std::cout << contents << std::endl; } catch (const std::exception& ex) { std::cerr << "yscan: " << ex.what() << std::endl; return 1; } return 0; }