add prompt if CMakeLists.txt already exists

toml-checker
Mohammed Alyousef 4 years ago
parent fa510bb00e
commit 887f9e4ece

@ -6,6 +6,7 @@
- Require cmake >= 3.15.
- Support settings and caching settings.
- Support config when running cmkr build.
- Add prompt prior to CMakeLists.txt generation if already existent in the current dir.
## 0.1.1 - 2020-11-19
- Add support for globbing.

@ -5,10 +5,13 @@
#include <exception>
#include <filesystem>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
namespace fs = std::filesystem;
namespace cmkr::args {
const char *handle_args(int argc, char **argv) {
std::vector<std::string> args;
@ -19,7 +22,20 @@ const char *handle_args(int argc, char **argv) {
return "Please provide command line arguments!";
std::string main_arg = args[1];
if (main_arg == "gen") {
auto ret = cmkr::gen::generate_cmake(std::filesystem::current_path().string().c_str());
bool cont = false;
if (args.size() > 2 && args[2] == "-y")
cont = true;
auto current_path = fs::current_path();
if (fs::exists(current_path / "CMakeLists.txt") && cont == false) {
std::cout << "A CMakeLists.txt file already exists in the current directory.\nWould you "
"like to overwrite it?[y/n]"
<< std::endl;
std::string resp;
std::cin >> resp;
if (resp != "y")
return "CMake generation aborted!";
}
auto ret = cmkr::gen::generate_cmake(current_path.string().c_str());
if (ret)
return "CMake generation error!";
return "CMake generation successful!";

Loading…
Cancel
Save