diff options
| author | zousar <[email protected]> | 2025-04-14 21:51:39 -0600 |
|---|---|---|
| committer | zousar <[email protected]> | 2025-04-14 21:51:39 -0600 |
| commit | 9cdfac225f0dc986ce449cbe8ef72faa39025971 (patch) | |
| tree | a965f2f904f5cb7c596281f2f14e40b2c8150834 /src/zen/cmds/builds_cmd.cpp | |
| parent | fix race condition in multipart download (#358) (diff) | |
| download | archived-zen-9cdfac225f0dc986ce449cbe8ef72faa39025971.tar.xz archived-zen-9cdfac225f0dc986ce449cbe8ef72faa39025971.zip | |
Add a list-container subcommand to zen builds command
Diffstat (limited to 'src/zen/cmds/builds_cmd.cpp')
| -rw-r--r-- | src/zen/cmds/builds_cmd.cpp | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/src/zen/cmds/builds_cmd.cpp b/src/zen/cmds/builds_cmd.cpp index cdcd79f58..2d24db956 100644 --- a/src/zen/cmds/builds_cmd.cpp +++ b/src/zen/cmds/builds_cmd.cpp @@ -8906,12 +8906,28 @@ BuildsCommand::BuildsCommand() m_Options.add_option("", "v", "verb", - "Verb for build - list, upload, download, diff, fetch-blob, validate-part", + "Verb for build - list-container, list, upload, download, diff, fetch-blob, validate-part", cxxopts::value(m_Verb), "<verb>"); m_Options.parse_positional({"verb"}); m_Options.positional_help("verb"); + // list-container + AddSystemOptions(m_ListContainerOptions); + AddCloudOptions(m_ListContainerOptions); + AddFileOptions(m_ListContainerOptions); + AddOutputOptions(m_ListContainerOptions); + AddZenFolderOptions(m_ListContainerOptions); + m_ListContainerOptions.add_options()("h,help", "Print help"); + m_ListContainerOptions.add_option("", + "", + "result-path", + "Path to json or compactbinary to write query result to", + cxxopts::value(m_ListResultPath), + "<result-path>"); + m_ListContainerOptions.parse_positional({"query-path", "result-path"}); + m_ListContainerOptions.positional_help("query-path result-path"); + // list AddSystemOptions(m_ListOptions); AddCloudOptions(m_ListOptions); @@ -9206,7 +9222,7 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) { throw zen::OptionParseException(fmt::format("url is not compatible with the storage-path option\n{}", m_Options.help())); } - if (m_Namespace.empty() || m_Bucket.empty()) + if (ToLower(m_Verb) != "list-container" && (m_Namespace.empty() || m_Bucket.empty())) { throw zen::OptionParseException( fmt::format("namespace and bucket options are required for url option\n{}", m_Options.help())); @@ -9596,6 +9612,57 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) try { + if (SubOption == &m_ListContainerOptions) + { + if (!m_ListResultPath.empty()) + { + ZEN_CONSOLE("Running {}: {}", GetRunningExecutablePath(), ZEN_CFG_VERSION_BUILD_STRING_FULL); + } + + BuildStorage::Statistics StorageStats; + BuildStorageCache::Statistics StorageCacheStats; + + const std::filesystem::path ZenFolderPath = m_ZenFolderPath.empty() + ? MakeSafeAbsolutePath(std::filesystem::current_path()) / ZenFolderName + : MakeSafeAbsolutePath(m_ZenFolderPath); + CreateDirectories(ZenFolderPath); + auto _ = MakeGuard([ZenFolderPath]() { + if (CleanDirectory(ZenFolderPath, {})) + { + std::error_code DummyEc; + RemoveDir(ZenFolderPath, DummyEc); + } + }); + + StorageInstance Storage = CreateBuildStorage(StorageStats, StorageCacheStats, ZenTempFolderPath(ZenFolderPath)); + + CbObject Response = Storage.BuildStorage->ListContainers(); + ZEN_ASSERT(ValidateCompactBinary(Response.GetView(), CbValidateMode::All) == CbValidateError::None); + if (m_ListResultPath.empty()) + { + ExtendableStringBuilder<1024> SB; + CompactBinaryToJson(Response.GetView(), SB); + ZEN_CONSOLE("{}", SB.ToView()); + } + else + { + std::filesystem::path ListResultPath = MakeSafeAbsolutePath(m_ListResultPath); + if (ToLower(ListResultPath.extension().string()) == ".cbo") + { + MemoryView ResponseView = Response.GetView(); + WriteFile(ListResultPath, IoBuffer(IoBuffer::Wrap, ResponseView.GetData(), ResponseView.GetSize())); + } + else + { + ExtendableStringBuilder<1024> SB; + CompactBinaryToJson(Response.GetView(), SB); + WriteFile(ListResultPath, IoBuffer(IoBuffer::Wrap, SB.Data(), SB.Size())); + } + } + + return 0; + } + if (SubOption == &m_ListOptions) { if (!m_ListResultPath.empty()) |