mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
cleanup command_line.cpp
This commit is contained in:
parent
4503455ae9
commit
46d3e5c7e1
1 changed files with 31 additions and 30 deletions
|
|
@ -13,22 +13,22 @@
|
|||
namespace fs = std::filesystem;
|
||||
|
||||
class ArgC {
|
||||
public:
|
||||
std::string keyword;
|
||||
std::function<bool()> execute;
|
||||
std::string args;
|
||||
std::string help;
|
||||
ArgC(
|
||||
const std::string& keyword,
|
||||
std::function<bool()> execute,
|
||||
const std::string& args,
|
||||
const std::string& help
|
||||
) {
|
||||
this->keyword = keyword;
|
||||
this->execute = execute;
|
||||
this->args = args;
|
||||
this->help = help;
|
||||
}
|
||||
public:
|
||||
std::string keyword;
|
||||
std::function<bool(CoreParameters&, util::ArgsReader&)> execute;
|
||||
std::string args;
|
||||
std::string help;
|
||||
ArgC(
|
||||
const std::string& keyword,
|
||||
std::function<bool(CoreParameters&, util::ArgsReader&)> execute,
|
||||
const std::string& args,
|
||||
const std::string& help
|
||||
) {
|
||||
this->keyword = keyword;
|
||||
this->execute = execute;
|
||||
this->args = args;
|
||||
this->help = help;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -36,60 +36,61 @@ static bool perform_keyword(
|
|||
util::ArgsReader& reader, const std::string& keyword, CoreParameters& params
|
||||
) {
|
||||
static const std::vector<ArgC> argumentsCommandline = {
|
||||
ArgC("--res", [¶ms, &reader]() -> bool {
|
||||
ArgC("--res", [](auto& params, auto& reader) -> bool {
|
||||
params.resFolder = reader.next();
|
||||
return true;
|
||||
}, "<path>", "set resources directory."),
|
||||
ArgC("--dir", [¶ms, &reader]() -> bool {
|
||||
ArgC("--dir", [](auto& params, auto& reader) -> bool {
|
||||
params.userFolder = reader.next();
|
||||
return true;
|
||||
}, "<path>", "set userfiles directory."),
|
||||
ArgC("--project", [¶ms, &reader]() -> bool {
|
||||
ArgC("--project", [](auto& params, auto& reader) -> bool {
|
||||
params.projectFolder = reader.next();
|
||||
return true;
|
||||
}, "<path>", "set project directory."),
|
||||
ArgC("--test", [¶ms, &reader]() -> bool {
|
||||
ArgC("--test", [](auto& params, auto& reader) -> bool {
|
||||
params.testMode = true;
|
||||
params.scriptFile = reader.next();
|
||||
return true;
|
||||
}, "<path>", "test script file."),
|
||||
ArgC("--script", [¶ms, &reader]() -> bool {
|
||||
ArgC("--script", [](auto& params, auto& reader) -> bool {
|
||||
params.testMode = false;
|
||||
params.scriptFile = reader.next();
|
||||
return true;
|
||||
}, "<path>", "main script file."),
|
||||
ArgC("--headless", [¶ms]() -> bool {
|
||||
ArgC("--headless", [](auto& params, auto& reader) -> bool {
|
||||
params.headless = true;
|
||||
return true;
|
||||
}, "", "run in headless mode."),
|
||||
ArgC("--stdin-cmd", [¶ms]() -> bool {
|
||||
ArgC("--stdin-cmd", [](auto& params, auto& reader) -> bool {
|
||||
params.stdinCommands = true;
|
||||
return true;
|
||||
}, "", "run commands from stdin."),
|
||||
ArgC("--tps", [¶ms, &reader]() -> bool {
|
||||
ArgC("--tps", [](auto& params, auto& reader) -> bool {
|
||||
params.tps = reader.nextInt();
|
||||
return true;
|
||||
}, "<tps>", "headless mode tick-rate (default - 20)."),
|
||||
ArgC("--version", []() -> bool {
|
||||
ArgC("--version", [](auto&, auto&) -> bool {
|
||||
std::cout << ENGINE_VERSION_STRING << std::endl;
|
||||
return false;
|
||||
}, "", "display the engine version."),
|
||||
ArgC("--dbg-server", [¶ms, &reader]() -> bool {
|
||||
ArgC("--dbg-server", [](auto& params, auto& reader) -> bool {
|
||||
params.debugServerString = reader.next();
|
||||
return true;
|
||||
}, "<serv>", "open debugging server where <serv> is {transport}:{port}"),
|
||||
ArgC("--sub-depth", [¶ms, &reader]() -> bool {
|
||||
ArgC("--sub-depth", [](auto& params, auto& reader) -> bool {
|
||||
params.subProcessDepth = reader.nextInt();
|
||||
return true;
|
||||
}, "<depth>", "sub-process depth"),
|
||||
ArgC("--help", []() -> bool {
|
||||
ArgC("--help", [](auto&, auto&) -> bool {
|
||||
std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n";
|
||||
std::cout << "Command-line arguments:\n";
|
||||
for (auto& arg : argumentsCommandline) {
|
||||
if (arg.help.empty()) {
|
||||
continue;
|
||||
}
|
||||
std::cout << std::setw(24) << std::left << (arg.keyword + " " + arg.args);
|
||||
std::cout << std::setw(24) << std::left
|
||||
<< (arg.keyword + " " + arg.args);
|
||||
std::cout << "- " << arg.help << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
|
@ -98,7 +99,7 @@ static bool perform_keyword(
|
|||
};
|
||||
for (auto& a : argumentsCommandline) {
|
||||
if (a.keyword == keyword) {
|
||||
return a.execute();
|
||||
return a.execute(params, reader);
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("unknown argument " + keyword);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue