aboutsummaryrefslogtreecommitdiff
path: root/src/zen/zen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zen/zen.cpp')
-rw-r--r--src/zen/zen.cpp232
1 files changed, 165 insertions, 67 deletions
diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp
index 09a2e4f91..9a466da2e 100644
--- a/src/zen/zen.cpp
+++ b/src/zen/zen.cpp
@@ -11,6 +11,7 @@
#include "cmds/cache_cmd.h"
#include "cmds/copy_cmd.h"
#include "cmds/dedup_cmd.h"
+#include "cmds/exec_cmd.h"
#include "cmds/info_cmd.h"
#include "cmds/print_cmd.h"
#include "cmds/projectstore_cmd.h"
@@ -21,6 +22,7 @@
#include "cmds/status_cmd.h"
#include "cmds/top_cmd.h"
#include "cmds/trace_cmd.h"
+#include "cmds/ui_cmd.h"
#include "cmds/up_cmd.h"
#include "cmds/version_cmd.h"
#include "cmds/vfs_cmd.h"
@@ -39,7 +41,8 @@
#include <zencore/trace.h>
#include <zencore/windows.h>
#include <zenhttp/httpcommon.h>
-#include <zenutil/environmentoptions.h>
+#include <zenutil/config/environmentoptions.h>
+#include <zenutil/consoletui.h>
#include <zenutil/logging.h>
#include <zenutil/workerpools.h>
#include <zenutil/zenserverprocess.h>
@@ -53,7 +56,6 @@
#include "progressbar.h"
#if ZEN_WITH_TESTS
-# define ZEN_TEST_WITH_RUNNER 1
# include <zencore/testing.h>
#endif
@@ -122,7 +124,7 @@ ZenCmdBase::ParseOptions(int argc, char** argv)
bool
ZenCmdBase::ParseOptions(cxxopts::Options& CmdOptions, int argc, char** argv)
{
- CmdOptions.set_width(GetConsoleColumns(80));
+ CmdOptions.set_width(TuiConsoleColumns(80));
cxxopts::ParseResult Result;
@@ -192,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)
{
@@ -316,22 +396,25 @@ main(int argc, char** argv)
}
#endif // ZEN_WITH_TRACE
- AttachCommand AttachCmd;
- BenchCommand BenchCmd;
- BuildsCommand BuildsCmd;
- CacheDetailsCommand CacheDetailsCmd;
- CacheGetCommand CacheGetCmd;
- CacheGenerateCommand CacheGenerateCmd;
- CacheInfoCommand CacheInfoCmd;
- CacheStatsCommand CacheStatsCmd;
- CopyCommand CopyCmd;
- CopyStateCommand CopyStateCmd;
- CreateOplogCommand CreateOplogCmd;
- CreateProjectCommand CreateProjectCmd;
- DedupCommand DedupCmd;
- DownCommand DownCmd;
- DropCommand DropCmd;
- DropProjectCommand ProjectDropCmd;
+ AttachCommand AttachCmd;
+ BenchCommand BenchCmd;
+ BuildsCommand BuildsCmd;
+ CacheDetailsCommand CacheDetailsCmd;
+ CacheGetCommand CacheGetCmd;
+ CacheGenerateCommand CacheGenerateCmd;
+ CacheInfoCommand CacheInfoCmd;
+ CacheStatsCommand CacheStatsCmd;
+ CopyCommand CopyCmd;
+ CopyStateCommand CopyStateCmd;
+ CreateOplogCommand CreateOplogCmd;
+ CreateProjectCommand CreateProjectCmd;
+ DedupCommand DedupCmd;
+ DownCommand DownCmd;
+ DropCommand DropCmd;
+ DropProjectCommand ProjectDropCmd;
+#if ZEN_WITH_COMPUTE_SERVICES
+ ExecCommand ExecCmd;
+#endif // ZEN_WITH_COMPUTE_SERVICES
ExportOplogCommand ExportOplogCmd;
FlushCommand FlushCmd;
GcCommand GcCmd;
@@ -360,6 +443,7 @@ main(int argc, char** argv)
LoggingCommand LoggingCmd;
TopCommand TopCmd;
TraceCommand TraceCmd;
+ UiCommand UiCmd;
UpCommand UpCmd;
VersionCommand VersionCmd;
VfsCommand VfsCmd;
@@ -375,53 +459,57 @@ main(int argc, char** argv)
const char* CmdSummary;
} Commands[] = {
// clang-format off
- {"attach", &AttachCmd, "Add a sponsor process to a running zen service"},
- {"bench", &BenchCmd, "Utility command for benchmarking"},
- {BuildsCommand::Name, &BuildsCmd, BuildsCommand::Description},
- {"cache-details", &CacheDetailsCmd, "Details on cache"},
- {"cache-info", &CacheInfoCmd, "Info on cache, namespace or bucket"},
+ {AttachCommand::Name, &AttachCmd, AttachCommand::Description},
+ {BenchCommand::Name, &BenchCmd, BenchCommand::Description},
+ {BuildsCommand::Name, &BuildsCmd, BuildsCommand::Description},
+ {CacheDetailsCommand::Name, &CacheDetailsCmd, CacheDetailsCommand::Description},
+ {CacheInfoCommand::Name, &CacheInfoCmd, CacheInfoCommand::Description},
{CacheGetCommand::Name, &CacheGetCmd, CacheGetCommand::Description},
{CacheGenerateCommand::Name, &CacheGenerateCmd, CacheGenerateCommand::Description},
- {"cache-stats", &CacheStatsCmd, "Stats on cache"},
- {"copy", &CopyCmd, "Copy file(s)"},
- {"copy-state", &CopyStateCmd, "Copy zen server disk state"},
- {"dedup", &DedupCmd, "Dedup files"},
- {"down", &DownCmd, "Bring zen server down"},
- {"drop", &DropCmd, "Drop cache namespace or bucket"},
- {"gc-status", &GcStatusCmd, "Garbage collect zen storage status check"},
- {"gc-stop", &GcStopCmd, "Request cancel of running garbage collection in zen storage"},
- {"gc", &GcCmd, "Garbage collect zen storage"},
- {"info", &InfoCmd, "Show high level Zen server information"},
- {"jobs", &JobCmd, "Show/cancel zen background jobs"},
- {"logs", &LoggingCmd, "Show/control zen logging"},
- {"oplog-create", &CreateOplogCmd, "Create a project oplog"},
- {"oplog-export", &ExportOplogCmd, "Export project store oplog"},
- {"oplog-import", &ImportOplogCmd, "Import project store oplog"},
- {"oplog-mirror", &OplogMirrorCmd, "Mirror project store oplog to file system"},
- {"oplog-snapshot", &SnapshotOplogCmd, "Snapshot project store oplog"},
+ {CacheStatsCommand::Name, &CacheStatsCmd, CacheStatsCommand::Description},
+ {CopyCommand::Name, &CopyCmd, CopyCommand::Description},
+ {CopyStateCommand::Name, &CopyStateCmd, CopyStateCommand::Description},
+ {DedupCommand::Name, &DedupCmd, DedupCommand::Description},
+ {DownCommand::Name, &DownCmd, DownCommand::Description},
+ {DropCommand::Name, &DropCmd, DropCommand::Description},
+#if ZEN_WITH_COMPUTE_SERVICES
+ {ExecCommand::Name, &ExecCmd, ExecCommand::Description},
+#endif
+ {GcStatusCommand::Name, &GcStatusCmd, GcStatusCommand::Description},
+ {GcStopCommand::Name, &GcStopCmd, GcStopCommand::Description},
+ {GcCommand::Name, &GcCmd, GcCommand::Description},
+ {InfoCommand::Name, &InfoCmd, InfoCommand::Description},
+ {JobCommand::Name, &JobCmd, JobCommand::Description},
+ {LoggingCommand::Name, &LoggingCmd, LoggingCommand::Description},
+ {CreateOplogCommand::Name, &CreateOplogCmd, CreateOplogCommand::Description},
+ {ExportOplogCommand::Name, &ExportOplogCmd, ExportOplogCommand::Description},
+ {ImportOplogCommand::Name, &ImportOplogCmd, ImportOplogCommand::Description},
+ {OplogMirrorCommand::Name, &OplogMirrorCmd, OplogMirrorCommand::Description},
+ {SnapshotOplogCommand::Name, &SnapshotOplogCmd, SnapshotOplogCommand::Description},
{OplogDownloadCommand::Name, &OplogDownload, OplogDownloadCommand::Description},
- {"oplog-validate", &OplogValidateCmd, "Validate oplog for missing references"},
- {"print", &PrintCmd, "Print compact binary object"},
- {"printpackage", &PrintPkgCmd, "Print compact binary package"},
- {"project-create", &CreateProjectCmd, "Create a project"},
- {"project-op-details", &ProjectOpDetailsCmd, "Detail info on ops inside a project store oplog"},
- {"project-drop", &ProjectDropCmd, "Drop project or project oplog"},
- {"project-info", &ProjectInfoCmd, "Info on project or project oplog"},
- {"project-stats", &ProjectStatsCmd, "Stats on project store"},
- {"ps", &PsCmd, "Enumerate running zen server instances"},
- {"rpc-record-replay", &RpcReplayCmd, "Replays a previously recorded session of rpc requests"},
- {"rpc-record-start", &RpcStartRecordingCmd, "Starts recording of cache rpc requests on a host"},
- {"rpc-record-stop", &RpcStopRecordingCmd, "Stops recording of cache rpc requests on a host"},
- {"run", &RunCmd, "Run command with special options"},
- {"scrub", &ScrubCmd, "Scrub zen storage (verify data integrity)"},
- {"serve", &ServeCmd, "Serve files from a directory"},
- {"status", &StatusCmd, "Show zen status"},
- {"top", &TopCmd, "Monitor zen server activity"},
- {"trace", &TraceCmd, "Control zen realtime tracing"},
- {"up", &UpCmd, "Bring zen server up"},
+ {OplogValidateCommand::Name, &OplogValidateCmd, OplogValidateCommand::Description},
+ {PrintCommand::Name, &PrintCmd, PrintCommand::Description},
+ {PrintPackageCommand::Name, &PrintPkgCmd, PrintPackageCommand::Description},
+ {CreateProjectCommand::Name, &CreateProjectCmd, CreateProjectCommand::Description},
+ {ProjectOpDetailsCommand::Name, &ProjectOpDetailsCmd, ProjectOpDetailsCommand::Description},
+ {DropProjectCommand::Name, &ProjectDropCmd, DropProjectCommand::Description},
+ {ProjectInfoCommand::Name, &ProjectInfoCmd, ProjectInfoCommand::Description},
+ {ProjectStatsCommand::Name, &ProjectStatsCmd, ProjectStatsCommand::Description},
+ {PsCommand::Name, &PsCmd, PsCommand::Description},
+ {RpcReplayCommand::Name, &RpcReplayCmd, RpcReplayCommand::Description},
+ {RpcStartRecordingCommand::Name, &RpcStartRecordingCmd, RpcStartRecordingCommand::Description},
+ {RpcStopRecordingCommand::Name, &RpcStopRecordingCmd, RpcStopRecordingCommand::Description},
+ {RunCommand::Name, &RunCmd, RunCommand::Description},
+ {ScrubCommand::Name, &ScrubCmd, ScrubCommand::Description},
+ {ServeCommand::Name, &ServeCmd, ServeCommand::Description},
+ {StatusCommand::Name, &StatusCmd, StatusCommand::Description},
+ {TopCommand::Name, &TopCmd, TopCommand::Description},
+ {TraceCommand::Name, &TraceCmd, TraceCommand::Description},
+ {UiCommand::Name, &UiCmd, UiCommand::Description},
+ {UpCommand::Name, &UpCmd, UpCommand::Description},
{VersionCommand::Name, &VersionCmd, VersionCommand::Description},
- {"vfs", &VfsCmd, "Manage virtual file system"},
- {"flush", &FlushCmd, "Flush storage"},
+ {VfsCommand::Name, &VfsCmd, VfsCommand::Description},
+ {FlushCommand::Name, &FlushCmd, FlushCommand::Description},
{WipeCommand::Name, &WipeCmd, WipeCommand::Description},
{WorkspaceCommand::Name, &WorkspaceCmd, WorkspaceCommand::Description},
{WorkspaceShareCommand::Name, &WorkspaceShareCmd, WorkspaceShareCommand::Description},
@@ -538,6 +626,9 @@ main(int argc, char** argv)
Options.add_options()("corelimit", "Limit concurrency", cxxopts::value(CoreLimit));
+ ZenLoggingCmdLineOptions LoggingCmdLineOptions;
+ LoggingCmdLineOptions.AddCliOptions(Options, GlobalOptions.LoggingConfig);
+
#if ZEN_WITH_TRACE
// We only have this in options for command line help purposes - we parse these argument separately earlier using
// GetTraceOptionsFromCommandline()
@@ -624,8 +715,8 @@ main(int argc, char** argv)
}
LimitHardwareConcurrency(CoreLimit);
-#if ZEN_USE_SENTRY
+#if ZEN_USE_SENTRY
{
EnvironmentOptions EnvOptions;
@@ -671,12 +762,19 @@ main(int argc, char** argv)
}
#endif
- zen::LoggingOptions LogOptions;
- LogOptions.IsDebug = GlobalOptions.IsDebug;
- LogOptions.IsVerbose = GlobalOptions.IsVerbose;
- LogOptions.AllowAsync = false;
+ LoggingCmdLineOptions.ApplyOptions(GlobalOptions.LoggingConfig);
+
+ const LoggingOptions LogOptions = {.IsDebug = GlobalOptions.IsDebug,
+ .IsVerbose = GlobalOptions.IsVerbose,
+ .IsTest = false,
+ .NoConsoleOutput = GlobalOptions.LoggingConfig.NoConsoleOutput,
+ .QuietConsole = GlobalOptions.LoggingConfig.QuietConsole,
+ .AbsLogFile = GlobalOptions.LoggingConfig.AbsLogFile,
+ .LogId = GlobalOptions.LoggingConfig.LogId};
zen::InitializeLogging(LogOptions);
+ ApplyLoggingOptions(Options, GlobalOptions.LoggingConfig);
+
std::set_terminate([]() {
void* Frames[8];
uint32_t FrameCount = GetCallstack(2, 8, Frames);