diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-10-29 17:16:47 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-10-29 17:16:47 +0100 |
| commit | 0b3acb991f11d9ace340f75bc2f8a454ea385fae (patch) | |
| tree | 15d9a49af39febab9576174a445a557df4f80174 /kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp | |
| parent | dfc45729d342f6f4d4d9ea39649c49b49fa178c6 (diff) | |
| download | apps-dev_tools-0b3acb991f11d9ace340f75bc2f8a454ea385fae.tar.gz | |
Got to a first satisfying state for this boilerplate generator
Diffstat (limited to 'kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp')
| -rw-r--r-- | kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp b/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp index 972feb7..2399f61 100644 --- a/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp +++ b/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp @@ -1,10 +1,106 @@ #include <forstio/error.hpp> + +#include "blueprints.hpp" + #include <iostream> +#include <filesystem> +#include <fstream> namespace kel { +saw::error_or<void> write_to_file( + std::string_view file_path, + std::string_view file_content +){ + namespace fs = std::filesystem; + try { + auto fpath = fs::path(file_path); + if(fpath.has_parent_path()){ + fs::create_directories(fs::path(fpath).parent_path()); + } + + std::ofstream out(fpath, std::ios::binary); + if(not out){ + return saw::make_error<saw::err::critical>("Couldn't create file"); + } + out.write(file_content.data(), static_cast<std::streamsize>(file_content.size())); + if(not out){ + return saw::make_error<saw::err::critical>("Couldn't write to file"); + } + }catch(const std::exception& e){ + (void) e; + return saw::make_error<saw::err::critical>("Couldn't create file somehow"); + } + + return saw::make_void(); +} + saw::error_or<void> kel_main(int argc, char** argv){ (void) argc; (void) argv; + + namespace fs = std::filesystem; + + try { + fs::path cwd = fs::current_path(); + std::cout << "\nCurrent working is directory: " << cwd << "\n\n"; + + } catch (const std::exception& e) { + return saw::make_error<saw::err::critical>("Couldn't get the working directory"); + } + { + std::string confirm; + std::cout << "Are you sure to proceed? Type 'yes' to continue: "; + std::getline(std::cin, confirm); + + if (confirm != "yes") { + std::cout<<"Didn't type \"yes\". Aborting..."<<std::endl; + return saw::make_void(); + } + } + + { + auto eov = write_to_file(readme_txt_file_path,readme_txt_file_content); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_to_file(default_nix_file_path,default_nix_file_content); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_to_file(sconstruct_file_path,sconstruct_file_content); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_to_file(sconscript_file_path,sconscript_file_content); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_to_file(main_cpp_file_path,main_cpp_file_content); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_to_file(gitignore_file_path,gitignore_file_content); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_to_file(derivation_nix_file_path,derivation_nix_file_content); + if(eov.is_error()){ + return eov; + } + } + return saw::make_void(); } } |
