From 887f9e4ececad9a49b7cf7ef6be968ac23497671 Mon Sep 17 00:00:00 2001 From: Mohammed Alyousef Date: Fri, 20 Nov 2020 19:28:15 +0300 Subject: [PATCH] add prompt if CMakeLists.txt already exists --- CHANGELOG.md | 1 + src/args.cpp | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e81f6e..eb8af2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/args.cpp b/src/args.cpp index fb2727f..59b6665 100644 --- a/src/args.cpp +++ b/src/args.cpp @@ -5,10 +5,13 @@ #include #include +#include #include #include #include +namespace fs = std::filesystem; + namespace cmkr::args { const char *handle_args(int argc, char **argv) { std::vector 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!";