mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 08:15:35 +00:00
Add --working-directory flag
This commit is contained in:
parent
265dd710cf
commit
7b99ccb08e
18
src/main.cpp
18
src/main.cpp
@ -30,6 +30,10 @@ ARGUMENTS:
|
||||
Server Config file, including the
|
||||
filename. For paths and filenames with
|
||||
spaces, put quotes around the path.
|
||||
--working-directory=/path/to/folder
|
||||
Sets the working directory of the Server.
|
||||
All paths are considered relative to this,
|
||||
including the path given in --path.
|
||||
--version
|
||||
Prints version info and exits.
|
||||
|
||||
@ -80,6 +84,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
||||
Parser.RegisterArgument({ "help" }, ArgsParser::NONE);
|
||||
Parser.RegisterArgument({ "version" }, ArgsParser::NONE);
|
||||
Parser.RegisterArgument({ "config" }, ArgsParser::HAS_VALUE);
|
||||
Parser.RegisterArgument({ "working-directory" }, ArgsParser::HAS_VALUE);
|
||||
Parser.Parse(Arguments.List);
|
||||
if (!Parser.Verify()) {
|
||||
return 1;
|
||||
@ -100,7 +105,18 @@ int BeamMPServerMain(MainArguments Arguments) {
|
||||
auto MaybeConfigPath = Parser.GetValueOfArgument({ "config" });
|
||||
if (MaybeConfigPath.has_value()) {
|
||||
ConfigPath = MaybeConfigPath.value();
|
||||
beammp_info("Custom config requested via commandline: '" + ConfigPath + "'");
|
||||
beammp_info("Custom config requested via commandline arguments: '" + ConfigPath + "'");
|
||||
}
|
||||
}
|
||||
if (Parser.FoundArgument({ "working-directory" })) {
|
||||
auto MaybeWorkingDirectory = Parser.GetValueOfArgument({ "working-directory" });
|
||||
if (MaybeWorkingDirectory.has_value()) {
|
||||
beammp_info("Custom working directory requested via commandline arguments: '" + ConfigPath + "'");
|
||||
try {
|
||||
fs::current_path(fs::path(MaybeWorkingDirectory.value()));
|
||||
} catch (const std::exception& e) {
|
||||
beammp_error("Could not set working directory to '" + MaybeWorkingDirectory.value() + "': " + e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user