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.
71 lines
2.0 KiB
71 lines
2.0 KiB
3 years ago
|
#include "arguments.hpp"
|
||
4 years ago
|
#include "build.hpp"
|
||
3 years ago
|
#include "cmake_generator.hpp"
|
||
4 years ago
|
#include "help.hpp"
|
||
4 years ago
|
|
||
4 years ago
|
#include "fs.hpp"
|
||
4 years ago
|
#include <exception>
|
||
4 years ago
|
#include <iostream>
|
||
4 years ago
|
#include <stdexcept>
|
||
4 years ago
|
#include <string>
|
||
|
#include <vector>
|
||
4 years ago
|
|
||
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]);
|
||
|
|
||
4 years ago
|
if (args.size() < 2)
|
||
4 years ago
|
throw std::runtime_error(cmkr::help::message());
|
||
4 years ago
|
std::string main_arg = args[1];
|
||
|
if (main_arg == "gen") {
|
||
4 years ago
|
auto ret = cmkr::gen::generate_cmake(fs::current_path().string().c_str());
|
||
4 years ago
|
if (ret)
|
||
|
return "CMake generation error!";
|
||
|
return "CMake generation successful!";
|
||
4 years ago
|
} else if (main_arg == "help") {
|
||
4 years ago
|
return cmkr::help::message();
|
||
4 years ago
|
} else if (main_arg == "version") {
|
||
4 years ago
|
return cmkr::help::version();
|
||
4 years ago
|
} else if (main_arg == "init") {
|
||
4 years ago
|
std::string type = "executable";
|
||
4 years ago
|
if (args.size() > 2)
|
||
4 years ago
|
type = args[2];
|
||
|
auto ret = cmkr::gen::generate_project(type.c_str());
|
||
4 years ago
|
if (ret)
|
||
|
return "Initialization failure!";
|
||
4 years ago
|
return "Directory initialized!";
|
||
4 years ago
|
} else if (main_arg == "build") {
|
||
4 years ago
|
auto ret = build::run(argc, argv);
|
||
4 years ago
|
if (ret)
|
||
4 years ago
|
return "CMake build error!";
|
||
|
return "CMake run completed!";
|
||
4 years ago
|
} else if (main_arg == "install") {
|
||
|
auto ret = build::install();
|
||
|
if (ret)
|
||
|
return "CMake install error!";
|
||
|
return "CMake install completed!";
|
||
4 years ago
|
} else if (main_arg == "clean") {
|
||
|
auto ret = build::clean();
|
||
|
if (ret)
|
||
|
return "CMake clean error!";
|
||
4 years ago
|
return "Cleaned build directory!";
|
||
4 years ago
|
} else {
|
||
4 years ago
|
throw std::runtime_error(cmkr::help::message());
|
||
4 years ago
|
}
|
||
|
}
|
||
4 years ago
|
} // namespace args
|
||
|
} // namespace cmkr
|
||
4 years ago
|
|
||
|
const char *cmkr_args_handle_args(int argc, char **argv) {
|
||
4 years ago
|
try {
|
||
|
return cmkr::args::handle_args(argc, argv);
|
||
|
} catch (const std::exception &e) {
|
||
|
return e.what();
|
||
|
} catch (...) {
|
||
4 years ago
|
return "Unknown error!";
|
||
4 years ago
|
}
|
||
4 years ago
|
}
|