// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "../zen.h" #include namespace zen { // Base for `cache` subcommands. Registers the shared --hosturl option; // host resolution is handled by ZenServiceClient at construction. class CacheSubCmdBase : public ZenSubCmdBase { public: CacheSubCmdBase(std::string_view Name, std::string_view Description); protected: std::string m_HostName; }; class CacheDetailsSubCmd : public CacheSubCmdBase { public: CacheDetailsSubCmd(); void Run(const ZenCliOptions& GlobalOptions) override; private: bool m_CSV = false; bool m_YAML = false; bool m_Details = false; bool m_AttachmentDetails = false; std::string m_Namespace; std::string m_Bucket; std::string m_ValueKey; }; class CacheDropSubCmd : public CacheSubCmdBase { public: CacheDropSubCmd(); void Run(const ZenCliOptions& GlobalOptions) override; private: std::string m_NamespaceName; std::string m_BucketName; }; class CacheGenSubCmd : public CacheSubCmdBase { public: CacheGenSubCmd(); void Run(const ZenCliOptions& GlobalOptions) override; private: std::string m_Namespace; std::string m_Bucket; uint64_t m_Count = 1; uint64_t m_MinSize = 0; uint64_t m_MaxSize = 0; uint32_t m_MinAttachmentCount = 0; uint32_t m_MaxAttachmentCount = 0; }; class CacheGetSubCmd : public CacheSubCmdBase { public: CacheGetSubCmd(); void Run(const ZenCliOptions& GlobalOptions) override; private: std::string m_Namespace; std::string m_Bucket; std::string m_ValueKey; std::string m_AttachmentHash; std::filesystem::path m_OutputPath; bool m_AsText = false; bool m_Decompress = true; }; class CacheInfoSubCmd : public CacheSubCmdBase { public: CacheInfoSubCmd(); void Run(const ZenCliOptions& GlobalOptions) override; private: std::string m_NamespaceName; std::string m_SizeInfoBucketNames; bool m_BucketSizeInfo = false; bool m_YAML = false; std::string m_BucketName; }; class CacheRecordSubCmd : public CacheSubCmdBase { public: CacheRecordSubCmd(); void Run(const ZenCliOptions& GlobalOptions) override; private: std::string m_Path; }; class CacheReplaySubCmd : public CacheSubCmdBase { public: CacheReplaySubCmd(); void Run(const ZenCliOptions& GlobalOptions) override; private: std::string m_RecordingPath; bool m_OnHost = false; bool m_ShowMethodStats = false; int m_ProcessCount = 1; int m_ThreadCount = 0; uint64_t m_Offset = 0; uint64_t m_Stride = 1; bool m_ForceAllowLocalRefs = false; bool m_DisableLocalRefs = false; bool m_ForceAllowLocalHandleRef = false; bool m_DisableLocalHandleRefs = false; bool m_ForceAllowPartialLocalRefs = false; bool m_DisablePartialLocalRefs = false; bool m_DryRun = false; }; class CacheStatsSubCmd : public CacheSubCmdBase { public: CacheStatsSubCmd(); void Run(const ZenCliOptions& GlobalOptions) override; private: bool m_YAML = false; }; class CacheCommand : public CacheStoreCmdWithSubCommands { public: static constexpr char Name[] = "cache"; static constexpr char Description[] = "Manage cache - info, stats, details, get, gen, drop, record, replay"; CacheCommand(); ~CacheCommand(); cxxopts::Options& Options() override { return m_Options; } private: cxxopts::Options m_Options{Name, Description}; CacheDetailsSubCmd m_DetailsSubCmd; CacheDropSubCmd m_DropSubCmd; CacheGenSubCmd m_GenSubCmd; CacheGetSubCmd m_GetSubCmd; CacheInfoSubCmd m_InfoSubCmd; CacheRecordSubCmd m_RecordSubCmd; CacheReplaySubCmd m_ReplaySubCmd; CacheStatsSubCmd m_StatsSubCmd; }; // --------------------------------------------------------------------------- // Deprecated legacy top-level commands. These forward to the corresponding // 'cache ' subcommand so that existing scripts keep working. They are // hidden from the top-level `zen --help` listing; `zen cache --help` is the // canonical discovery surface now. namespace cache_legacy_shim { void RunAs(const char* SubCommandName, const ZenCliOptions& GlobalOptions, int argc, char** argv); } class DeprecatedCacheStoreCommand : public CacheStoreCommand { public: bool IsHidden() const override { return true; } }; class DropCommand : public DeprecatedCacheStoreCommand { public: static constexpr char Name[] = "drop"; static constexpr char Description[] = "(deprecated, use 'cache drop') Drop cache namespace or bucket"; void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override { cache_legacy_shim::RunAs("drop", GlobalOptions, argc, argv); } cxxopts::Options& Options() override { return m_Options; } private: cxxopts::Options m_Options{Name, Description}; }; class CacheInfoCommand : public DeprecatedCacheStoreCommand { public: static constexpr char Name[] = "cache-info"; static constexpr char Description[] = "(deprecated, use 'cache info') Info on cache, namespace or bucket"; void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override { cache_legacy_shim::RunAs("info", GlobalOptions, argc, argv); } cxxopts::Options& Options() override { return m_Options; } private: cxxopts::Options m_Options{Name, Description}; }; class CacheStatsCommand : public DeprecatedCacheStoreCommand { public: static constexpr char Name[] = "cache-stats"; static constexpr char Description[] = "(deprecated, use 'cache stats') Stats on cache"; void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override { cache_legacy_shim::RunAs("stats", GlobalOptions, argc, argv); } cxxopts::Options& Options() override { return m_Options; } private: cxxopts::Options m_Options{Name, Description}; }; class CacheDetailsCommand : public DeprecatedCacheStoreCommand { public: static constexpr char Name[] = "cache-details"; static constexpr char Description[] = "(deprecated, use 'cache details') Details on cache"; void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override { cache_legacy_shim::RunAs("details", GlobalOptions, argc, argv); } cxxopts::Options& Options() override { return m_Options; } private: cxxopts::Options m_Options{Name, Description}; }; class CacheGenerateCommand : public DeprecatedCacheStoreCommand { public: static constexpr char Name[] = "cache-gen"; static constexpr char Description[] = "(deprecated, use 'cache gen') Generates cache values into a bucket"; void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override { cache_legacy_shim::RunAs("gen", GlobalOptions, argc, argv); } cxxopts::Options& Options() override { return m_Options; } private: cxxopts::Options m_Options{Name, Description}; }; class CacheGetCommand : public DeprecatedCacheStoreCommand { public: static constexpr char Name[] = "cache-get"; static constexpr char Description[] = "(deprecated, use 'cache get') Get cache values/records or attachments from a bucket"; void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override { cache_legacy_shim::RunAs("get", GlobalOptions, argc, argv); } cxxopts::Options& Options() override { return m_Options; } private: cxxopts::Options m_Options{Name, Description}; }; class RpcStartRecordingCommand : public DeprecatedCacheStoreCommand { public: static constexpr char Name[] = "rpc-record-start"; static constexpr char Description[] = "(deprecated, use 'cache record ') Starts recording of cache rpc requests on a host"; void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override { cache_legacy_shim::RunAs("record", GlobalOptions, argc, argv); } cxxopts::Options& Options() override { return m_Options; } private: cxxopts::Options m_Options{Name, Description}; }; class RpcStopRecordingCommand : public DeprecatedCacheStoreCommand { public: static constexpr char Name[] = "rpc-record-stop"; static constexpr char Description[] = "(deprecated, use 'cache record stop') Stops recording of cache rpc requests on a host"; void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override; cxxopts::Options& Options() override { return m_Options; } private: cxxopts::Options m_Options{Name, Description}; }; class RpcReplayCommand : public DeprecatedCacheStoreCommand { public: static constexpr char Name[] = "rpc-record-replay"; static constexpr char Description[] = "(deprecated, use 'cache replay') Replays a previously recorded session of rpc requests"; void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override { cache_legacy_shim::RunAs("replay", GlobalOptions, argc, argv); } cxxopts::Options& Options() override { return m_Options; } private: cxxopts::Options m_Options{Name, Description}; }; } // namespace zen