add prompt if CMakeLists.txt already exists

This commit is contained in:
Mohammed Alyousef
2020-11-20 19:28:15 +03:00
parent fa510bb00e
commit 887f9e4ece
2 changed files with 18 additions and 1 deletions
+17 -1
View File
@@ -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!";