diff options
| author | Dan Engelbrecht <[email protected]> | 2023-09-01 07:29:41 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-01 13:29:41 +0200 |
| commit | a165efeaf58dc7336e40d812359b0fc2ce0e7a83 (patch) | |
| tree | 6c7aa1dd0cbb7f0fa751f7bc1bff9b3e8205e1da /src/zenserver/config.cpp | |
| parent | 0.2.19 (diff) | |
| download | zen-a165efeaf58dc7336e40d812359b0fc2ce0e7a83.tar.xz zen-a165efeaf58dc7336e40d812359b0fc2ce0e7a83.zip | |
add `--write-config` to zenserver options (#382)
- Feature: `zen up` command has two new command line options
- `--config <file_path>` tells zenserver to start with a specific config file
- `--owner-pid <pid>` tells zenserver to start with a owning process id
- Feature: `zen attach` command to add additional owning processes to a running zenserver instance
- `--owner-pid <pid>` adds pid to running zenserver instance list of owning processes
- Feature: `--write-config` command line option for zenserver
- `--write-config <file_path>` path to a file which will contain a lua config file for zenserver combining all command line options and optional lua config files
- Improvement: `zen up` command will check if zenserver is currently running before starting up a new instance
Diffstat (limited to 'src/zenserver/config.cpp')
| -rw-r--r-- | src/zenserver/config.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp index 2d286b02a..1f5a3eb21 100644 --- a/src/zenserver/config.cpp +++ b/src/zenserver/config.cpp @@ -10,6 +10,7 @@ #include <zencore/iobuffer.h> #include <zencore/string.h> #include <zenhttp/zenhttp.h> +#include <zenutil/basicfile.h> ZEN_THIRD_PARTY_INCLUDES_START #include <fmt/format.h> @@ -136,15 +137,15 @@ ParseBucketConfigs(std::span<std::string> Buckets) } static std::string -MakeSafePath(const std::string& Path) +MakeSafePath(const std::string_view Path) { #if ZEN_PLATFORM_WINDOWS if (Path.empty()) { - return Path; + return std::string(Path); } - std::string FixedPath = Path; + std::string FixedPath(Path); std::replace(FixedPath.begin(), FixedPath.end(), '/', '\\'); if (!FixedPath.starts_with("\\\\?\\")) { @@ -152,7 +153,7 @@ MakeSafePath(const std::string& Path) } return FixedPath; #else - return Path; + return std::string(Path); #endif }; @@ -768,7 +769,10 @@ private: } // namespace LuaConfig void -ParseConfigFile(const std::filesystem::path& Path, ZenServerOptions& ServerOptions, const cxxopts::ParseResult& CmdLineResult) +ParseConfigFile(const std::filesystem::path& Path, + ZenServerOptions& ServerOptions, + const cxxopts::ParseResult& CmdLineResult, + std::string_view OutputConfigFile) { using namespace std::literals; @@ -923,6 +927,16 @@ ParseConfigFile(const std::filesystem::path& Path, ZenServerOptions& ServerOptio { LuaOptions.Touch("server.objectstore.buckets"sv); } + + if (!OutputConfigFile.empty()) + { + std::filesystem::path WritePath(MakeSafePath(OutputConfigFile)); + zen::ExtendableStringBuilder<512> ConfigStringBuilder; + LuaOptions.Print(ConfigStringBuilder, CmdLineResult); + zen::BasicFile Output; + Output.Open(WritePath, zen::BasicFile::Mode::kTruncate); + Output.Write(ConfigStringBuilder.Data(), ConfigStringBuilder.Size(), 0); + } } void @@ -943,6 +957,7 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) std::string ContentDir; std::string AbsLogFile; std::string ConfigFile; + std::string OutputConfigFile; cxxopts::Options options("zenserver", "Zen Server"); options.add_options()("dedicated", @@ -956,6 +971,7 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) options.add_options()("content-dir", "Frontend content directory", cxxopts::value<std::string>(ContentDir)); options.add_options()("abslog", "Path to log file", cxxopts::value<std::string>(AbsLogFile)); options.add_options()("config", "Path to Lua config file", cxxopts::value<std::string>(ConfigFile)); + options.add_options()("write-config", "Path to output Lua config file", cxxopts::value<std::string>(OutputConfigFile)); options.add_options()("no-sentry", "Disable Sentry crash handler", cxxopts::value<bool>(ServerOptions.NoSentry)->default_value("false")); @@ -1380,11 +1396,11 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) if (!ServerOptions.ConfigFile.empty()) { - ParseConfigFile(ServerOptions.ConfigFile, ServerOptions, result); + ParseConfigFile(ServerOptions.ConfigFile, ServerOptions, result, OutputConfigFile); } else { - ParseConfigFile(ServerOptions.DataDir / "zen_cfg.lua", ServerOptions, result); + ParseConfigFile(ServerOptions.DataDir / "zen_cfg.lua", ServerOptions, result, OutputConfigFile); } ValidateOptions(ServerOptions); |