aboutsummaryrefslogtreecommitdiff
path: root/src/zen/zen.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-03-09 17:43:08 +0100
committerGitHub Enterprise <[email protected]>2026-03-09 17:43:08 +0100
commitb37b34ea6ad906f54e8104526e77ba66aed997da (patch)
treee80ce17d666aff6d2f0d73d4977128ffb4055476 /src/zen/zen.cpp
parentadd fallback for zencache multirange (#816) (diff)
downloadarchived-zen-b37b34ea6ad906f54e8104526e77ba66aed997da.tar.xz
archived-zen-b37b34ea6ad906f54e8104526e77ba66aed997da.zip
Dashboard overhaul, compute integration (#814)
- **Frontend dashboard overhaul**: Unified compute/main dashboards into a single shared UI. Added new pages for cache, projects, metrics, sessions, info (build/runtime config, system stats). Added live-update via WebSockets with pause control, sortable detail tables, themed styling. Refactored compute/hub/orchestrator pages into modular JS. - **HTTP server fixes and stats**: Fixed http.sys local-only fallback when default port is in use, implemented root endpoint redirect for http.sys, fixed Linux/Mac port reuse. Added /stats endpoint exposing HTTP server metrics (bytes transferred, request rates). Added WebSocket stats tracking. - **OTEL/diagnostics hardening**: Improved OTLP HTTP exporter with better error handling and resilience. Extended diagnostics services configuration. - **Session management**: Added new sessions service with HTTP endpoints for registering, updating, querying, and removing sessions. Includes session log file support. This is still WIP. - **CLI subcommand support**: Added support for commands with subcommands in the zen CLI tool, with improved command dispatch. - **Misc**: Exposed CPU usage/hostname to frontend, fixed JS compact binary float32/float64 decoding, limited projects displayed on front page to 25 sorted by last access, added vscode:// link support. Also contains some fixes from TSAN analysis.
Diffstat (limited to 'src/zen/zen.cpp')
-rw-r--r--src/zen/zen.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp
index 7f7afa322..9a466da2e 100644
--- a/src/zen/zen.cpp
+++ b/src/zen/zen.cpp
@@ -194,6 +194,84 @@ ZenCmdBase::GetSubCommand(cxxopts::Options&,
return argc;
}
+ZenSubCmdBase::ZenSubCmdBase(std::string_view Name, std::string_view Description)
+: m_SubOptions(std::string(Name), std::string(Description))
+{
+ m_SubOptions.add_options()("h,help", "Print help");
+}
+
+void
+ZenCmdWithSubCommands::AddSubCommand(ZenSubCmdBase& SubCmd)
+{
+ m_SubCommands.push_back(&SubCmd);
+}
+
+bool
+ZenCmdWithSubCommands::OnParentOptionsParsed(const ZenCliOptions& /*GlobalOptions*/)
+{
+ return true;
+}
+
+void
+ZenCmdWithSubCommands::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
+{
+ std::vector<cxxopts::Options*> SubOptionPtrs;
+ SubOptionPtrs.reserve(m_SubCommands.size());
+ for (ZenSubCmdBase* SubCmd : m_SubCommands)
+ {
+ SubOptionPtrs.push_back(&SubCmd->SubOptions());
+ }
+
+ cxxopts::Options* MatchedSubOption = nullptr;
+ std::vector<char*> SubCommandArguments;
+ int ParentArgc = GetSubCommand(Options(), argc, argv, SubOptionPtrs, MatchedSubOption, SubCommandArguments);
+
+ if (!ParseOptions(Options(), ParentArgc, argv))
+ {
+ return;
+ }
+
+ if (MatchedSubOption == nullptr)
+ {
+ ExtendableStringBuilder<128> VerbList;
+ for (bool First = true; ZenSubCmdBase * SubCmd : m_SubCommands)
+ {
+ if (!First)
+ {
+ VerbList.Append(", ");
+ }
+ VerbList.Append(SubCmd->SubOptions().program());
+ First = false;
+ }
+ throw OptionParseException(fmt::format("No subcommand specified. Available subcommands: {}", VerbList.ToView()), Options().help());
+ }
+
+ ZenSubCmdBase* MatchedSubCmd = nullptr;
+ for (ZenSubCmdBase* SubCmd : m_SubCommands)
+ {
+ if (&SubCmd->SubOptions() == MatchedSubOption)
+ {
+ MatchedSubCmd = SubCmd;
+ break;
+ }
+ }
+ ZEN_ASSERT(MatchedSubCmd != nullptr);
+
+ // Parse subcommand args before OnParentOptionsParsed so --help on the subcommand
+ // works without requiring parent options like --hosturl to be populated.
+ if (!ParseOptions(*MatchedSubOption, gsl::narrow<int>(SubCommandArguments.size()), SubCommandArguments.data()))
+ {
+ return;
+ }
+
+ if (!OnParentOptionsParsed(GlobalOptions))
+ {
+ return;
+ }
+
+ MatchedSubCmd->Run(GlobalOptions);
+}
+
static ReturnCode
GetReturnCodeFromHttpResult(const HttpClientError& Ex)
{