mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 21:11:50 +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;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
class ArgC {
|
class ArgC {
|
||||||
public:
|
public:
|
||||||
std::string keyword;
|
std::string keyword;
|
||||||
std::function<bool()> execute;
|
std::function<bool(CoreParameters&, util::ArgsReader&)> execute;
|
||||||
std::string args;
|
std::string args;
|
||||||
std::string help;
|
std::string help;
|
||||||
ArgC(
|
ArgC(
|
||||||
const std::string& keyword,
|
const std::string& keyword,
|
||||||
std::function<bool()> execute,
|
std::function<bool(CoreParameters&, util::ArgsReader&)> execute,
|
||||||
const std::string& args,
|
const std::string& args,
|
||||||
const std::string& help
|
const std::string& help
|
||||||
) {
|
) {
|
||||||
this->keyword = keyword;
|
this->keyword = keyword;
|
||||||
this->execute = execute;
|
this->execute = execute;
|
||||||
this->args = args;
|
this->args = args;
|
||||||
this->help = help;
|
this->help = help;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -36,60 +36,61 @@ static bool perform_keyword(
|
||||||
util::ArgsReader& reader, const std::string& keyword, CoreParameters& params
|
util::ArgsReader& reader, const std::string& keyword, CoreParameters& params
|
||||||
) {
|
) {
|
||||||
static const std::vector<ArgC> argumentsCommandline = {
|
static const std::vector<ArgC> argumentsCommandline = {
|
||||||
ArgC("--res", [¶ms, &reader]() -> bool {
|
ArgC("--res", [](auto& params, auto& reader) -> bool {
|
||||||
params.resFolder = reader.next();
|
params.resFolder = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<path>", "set resources directory."),
|
}, "<path>", "set resources directory."),
|
||||||
ArgC("--dir", [¶ms, &reader]() -> bool {
|
ArgC("--dir", [](auto& params, auto& reader) -> bool {
|
||||||
params.userFolder = reader.next();
|
params.userFolder = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<path>", "set userfiles directory."),
|
}, "<path>", "set userfiles directory."),
|
||||||
ArgC("--project", [¶ms, &reader]() -> bool {
|
ArgC("--project", [](auto& params, auto& reader) -> bool {
|
||||||
params.projectFolder = reader.next();
|
params.projectFolder = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<path>", "set project directory."),
|
}, "<path>", "set project directory."),
|
||||||
ArgC("--test", [¶ms, &reader]() -> bool {
|
ArgC("--test", [](auto& params, auto& reader) -> bool {
|
||||||
params.testMode = true;
|
params.testMode = true;
|
||||||
params.scriptFile = reader.next();
|
params.scriptFile = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<path>", "test script file."),
|
}, "<path>", "test script file."),
|
||||||
ArgC("--script", [¶ms, &reader]() -> bool {
|
ArgC("--script", [](auto& params, auto& reader) -> bool {
|
||||||
params.testMode = false;
|
params.testMode = false;
|
||||||
params.scriptFile = reader.next();
|
params.scriptFile = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<path>", "main script file."),
|
}, "<path>", "main script file."),
|
||||||
ArgC("--headless", [¶ms]() -> bool {
|
ArgC("--headless", [](auto& params, auto& reader) -> bool {
|
||||||
params.headless = true;
|
params.headless = true;
|
||||||
return true;
|
return true;
|
||||||
}, "", "run in headless mode."),
|
}, "", "run in headless mode."),
|
||||||
ArgC("--stdin-cmd", [¶ms]() -> bool {
|
ArgC("--stdin-cmd", [](auto& params, auto& reader) -> bool {
|
||||||
params.stdinCommands = true;
|
params.stdinCommands = true;
|
||||||
return true;
|
return true;
|
||||||
}, "", "run commands from stdin."),
|
}, "", "run commands from stdin."),
|
||||||
ArgC("--tps", [¶ms, &reader]() -> bool {
|
ArgC("--tps", [](auto& params, auto& reader) -> bool {
|
||||||
params.tps = reader.nextInt();
|
params.tps = reader.nextInt();
|
||||||
return true;
|
return true;
|
||||||
}, "<tps>", "headless mode tick-rate (default - 20)."),
|
}, "<tps>", "headless mode tick-rate (default - 20)."),
|
||||||
ArgC("--version", []() -> bool {
|
ArgC("--version", [](auto&, auto&) -> bool {
|
||||||
std::cout << ENGINE_VERSION_STRING << std::endl;
|
std::cout << ENGINE_VERSION_STRING << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}, "", "display the engine version."),
|
}, "", "display the engine version."),
|
||||||
ArgC("--dbg-server", [¶ms, &reader]() -> bool {
|
ArgC("--dbg-server", [](auto& params, auto& reader) -> bool {
|
||||||
params.debugServerString = reader.next();
|
params.debugServerString = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<serv>", "open debugging server where <serv> is {transport}:{port}"),
|
}, "<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();
|
params.subProcessDepth = reader.nextInt();
|
||||||
return true;
|
return true;
|
||||||
}, "<depth>", "sub-process depth"),
|
}, "<depth>", "sub-process depth"),
|
||||||
ArgC("--help", []() -> bool {
|
ArgC("--help", [](auto&, auto&) -> bool {
|
||||||
std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n";
|
std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n";
|
||||||
std::cout << "Command-line arguments:\n";
|
std::cout << "Command-line arguments:\n";
|
||||||
for (auto& arg : argumentsCommandline) {
|
for (auto& arg : argumentsCommandline) {
|
||||||
if (arg.help.empty()) {
|
if (arg.help.empty()) {
|
||||||
continue;
|
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 << "- " << arg.help << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
@ -98,7 +99,7 @@ static bool perform_keyword(
|
||||||
};
|
};
|
||||||
for (auto& a : argumentsCommandline) {
|
for (auto& a : argumentsCommandline) {
|
||||||
if (a.keyword == keyword) {
|
if (a.keyword == keyword) {
|
||||||
return a.execute();
|
return a.execute(params, reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error("unknown argument " + keyword);
|
throw std::runtime_error("unknown argument " + keyword);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue