MCPcopy Create free account
hub / github.com/build-cpp/cmkr / handle_args

Function handle_args

src/arguments.cpp:13–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11namespace cmkr {
12namespace args {
13const char *handle_args(int argc, char **argv) {
14 std::vector<std::string> args;
15 for (int i = 0; i < argc; ++i)
16 args.push_back(argv[i]);
17
18 if (args.size() < 2)
19 throw std::runtime_error(cmkr::help::message());
20 std::string main_arg = args[1];
21 if (main_arg == "gen") {
22 cmkr::gen::generate_cmake(fs::current_path().string().c_str());
23 return "CMake generation successful!";
24 } else if (main_arg == "help") {
25 return cmkr::help::message();
26 } else if (main_arg == "version") {
27 return cmkr::help::version();
28 } else if (main_arg == "init") {
29 std::string type = "executable";
30 if (args.size() > 2)
31 type = args[2];
32 cmkr::gen::generate_project(type.c_str());
33 cmkr::gen::generate_cmake(fs::current_path().string().c_str());
34 return "Directory initialized!";
35 } else if (main_arg == "build") {
36 auto ret = build::run(argc, argv);
37 if (ret)
38 throw std::runtime_error("CMake build failed!");
39 return "CMake build completed!";
40 } else if (main_arg == "install") {
41 auto ret = build::install();
42 if (ret)
43 throw std::runtime_error("CMake install failed!");
44 return "CMake install completed!";
45 } else if (main_arg == "clean") {
46 auto ret = build::clean();
47 if (ret)
48 throw std::runtime_error("CMake clean failed!");
49 return "Cleaned build directory!";
50 } else {
51 throw std::runtime_error(cmkr::help::message());
52 }
53}
54} // namespace args
55} // namespace cmkr

Callers 1

mainFunction · 0.85

Calls 7

messageFunction · 0.85
generate_cmakeFunction · 0.85
generate_projectFunction · 0.85
runFunction · 0.85
installFunction · 0.85
cleanFunction · 0.85
versionFunction · 0.70

Tested by

no test coverage detected