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/args.cpp

54 lines
1.6 KiB

4 years ago
#include "args.h"
#include "gen.h"
#include "help.h"
#include <filesystem>
#include <stddef.h>
#include <stdexcept>
4 years ago
#include <stdlib.h>
#include <string>
#include <vector>
namespace cmkr::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("Please provide command line arguments!");
std::string main_arg = args[1];
if (main_arg == "gen") {
4 years ago
cmkr::gen::generate_cmake(std::filesystem::current_path().string().c_str());
return "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") {
if (args.size() < 3)
throw std::runtime_error("Please provide a project type!");
4 years ago
cmkr::gen::generate_project(args[2].c_str());
return "Directory initialized!";
} else if (main_arg == "build") {
std::string command = "cmake -S. -Bbin ";
if (args.size() > 2) {
4 years ago
for (size_t i = 2; i < args.size(); ++i) {
command += args[i] + " ";
}
}
command += "&& cmake --build bin";
4 years ago
auto ret = system(command.c_str());
if (ret)
return "Run faced an error!";
return "Run completed!";
} else {
return "Unknown argument!";
}
}
4 years ago
} // namespace cmkr::args
const char *cmkr_args_handle_args(int argc, char **argv) {
return cmkr::args::handle_args(argc, argv);
}