You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cmkr/src/arguments.cpp

58 lines
1.8 KiB

#include "arguments.hpp"
#include "build.hpp"
#include "cmake_generator.hpp"
#include "help.hpp"
4 years ago
#include "fs.hpp"
4 years ago
#include <exception>
#include <iostream>
#include <stdexcept>
4 years ago
#include <string>
#include <vector>
4 years ago
namespace cmkr {
namespace args {
4 years ago
const char *handle_args(int argc, char **argv) {
std::vector<std::string> args;
for (int i = 0; i < argc; ++i)
args.push_back(argv[i]);
if (args.size() < 2)
throw std::runtime_error(cmkr::help::message());
std::string main_arg = args[1];
if (main_arg == "gen") {
cmkr::gen::generate_cmake(fs::current_path().string().c_str());
4 years ago
return "CMake generation successful!";
} else if (main_arg == "help") {
4 years ago
return cmkr::help::message();
} else if (main_arg == "version") {
4 years ago
return cmkr::help::version();
} else if (main_arg == "init") {
std::string type = "executable";
4 years ago
if (args.size() > 2)
type = args[2];
cmkr::gen::generate_project(type.c_str());
cmkr::gen::generate_cmake(fs::current_path().string().c_str());
return "Directory initialized!";
} else if (main_arg == "build") {
4 years ago
auto ret = build::run(argc, argv);
4 years ago
if (ret)
throw std::runtime_error("CMake build failed!");
return "CMake build completed!";
4 years ago
} else if (main_arg == "install") {
auto ret = build::install();
if (ret)
throw std::runtime_error("CMake install failed!");
4 years ago
return "CMake install completed!";
} else if (main_arg == "clean") {
auto ret = build::clean();
if (ret)
throw std::runtime_error("CMake clean failed!");
4 years ago
return "Cleaned build directory!";
} else {
throw std::runtime_error(cmkr::help::message());
}
}
4 years ago
} // namespace args
} // namespace cmkr