diff options
| author | Dan Engelbrecht <[email protected]> | 2023-09-22 08:22:06 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-22 14:22:06 +0200 |
| commit | c7d4dc6a4d13881028d566f5ce501335e47e48bf (patch) | |
| tree | 493110da583a8e5d97fe05e14f23469ee6244d2b /src/zen/cmds/version_cmd.cpp | |
| parent | add trace command to enable/disable tracing at runtime (#416) (diff) | |
| download | archived-zen-c7d4dc6a4d13881028d566f5ce501335e47e48bf.tar.xz archived-zen-c7d4dc6a4d13881028d566f5ce501335e47e48bf.zip | |
Collect all zen admin-related commands into admin.h/.cpp (#418)
* move commands in scrub.h/cpp to admin_cmd.h/cpp
* move job command into admin_cmd.h/.cpp
* admin -> admin_cmd
* bench -> bench_cmd
* cache -> cache_cmd
* copy -> copy_cmd
* dedup -> dedup_cmd
* hash -> hash_cmd
* print -> print_cmd
* projectstore -> projectstore_cmd
* rpcreplay -> rpcreplay_cmd
* serve -> serve_cmd
* status -> status_cmd
* top -> top_cmd
* trace -> trace_cmd
* up -> up_cmd
* version -> version_cmd
Diffstat (limited to 'src/zen/cmds/version_cmd.cpp')
| -rw-r--r-- | src/zen/cmds/version_cmd.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/zen/cmds/version_cmd.cpp b/src/zen/cmds/version_cmd.cpp new file mode 100644 index 000000000..bd31862b4 --- /dev/null +++ b/src/zen/cmds/version_cmd.cpp @@ -0,0 +1,79 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "version_cmd.h" + +#include <zencore/config.h> +#include <zencore/filesystem.h> +#include <zencore/fmtutils.h> +#include <zencore/logging.h> +#include <zenhttp/httpcommon.h> +#include <zenutil/zenserverprocess.h> + +#include <memory> + +ZEN_THIRD_PARTY_INCLUDES_START +#include <cpr/cpr.h> +ZEN_THIRD_PARTY_INCLUDES_END + +namespace zen { + +VersionCommand::VersionCommand() +{ + m_Options.add_options()("h,help", "Print help"); + m_Options.add_option("", "u", "hosturl", "Host URL", cxxopts::value(m_HostName), "[hosturl]"); + m_Options.add_option("", "d", "detailed", "Detailed Version", cxxopts::value(m_DetailedVersion), "[detailedversion]"); + m_Options.parse_positional({"hosturl"}); +} + +VersionCommand::~VersionCommand() = default; + +int +VersionCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) +{ + ZEN_UNUSED(GlobalOptions); + if (!ParseOptions(argc, argv)) + { + return 0; + } + + std::string Version; + + if (m_HostName.empty()) + { + if (m_DetailedVersion) + { + Version = ZEN_CFG_VERSION_BUILD_STRING_FULL; + } + else + { + Version = ZEN_CFG_VERSION; + } + } + else + { + const std::string UrlBase = fmt::format("{}/health", m_HostName); + cpr::Session Session; + std::string VersionRequest = fmt::format("{}/version{}", UrlBase, m_DetailedVersion ? "?detailed=true" : ""); + Session.SetUrl(VersionRequest); + cpr::Response Response = Session.Get(); + if (!zen::IsHttpSuccessCode(Response.status_code)) + { + if (Response.status_code) + { + ZEN_ERROR("{} failed: {}: {} ({})", VersionRequest, Response.status_code, Response.reason, Response.text); + } + else + { + ZEN_ERROR("{} failed: {}", VersionRequest, Response.error.message); + } + + return 1; + } + Version = Response.text; + } + + zen::ConsoleLog().info("{}", Version); + + return 0; +} +} // namespace zen |