From 163ff91bffc726d9592def1ca785d4bfeda949ca Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 25 Mar 2021 23:44:29 +0100 Subject: [PATCH] cli: Add basic listing of build actions --- cli/main.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/cli/main.cpp b/cli/main.cpp index 66bb942..320d84f 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -1,5 +1,7 @@ #include "resources/config.h" +#include "../librepomgr/buildactions/buildaction.h" +#include "../librepomgr/buildactions/buildactionmeta.h" #include "../librepomgr/json.h" #include "../librepomgr/webapi/params.h" #include "../librepomgr/webclient/session.h" @@ -224,6 +226,33 @@ void printPackageDetails(const LibRepoMgr::WebClient::Response::body_type::value std::cout.flush(); } +void printListOfBuildActions(const LibRepoMgr::WebClient::Response::body_type::value_type &jsonData) +{ + const auto actions = ReflectiveRapidJSON::JsonReflector::fromJson>(jsonData.data(), jsonData.size()); + const auto meta = LibRepoMgr::BuildActionMetaInfo(); + const auto unknown = std::string_view("?"); + auto t = tabulate::Table(); + t.format().hide_border(); + t.add_row( + { "ID", "Task", "Type", "Status", "Result", "Created", "Started", "Runtime", "Directory", "Source repo", "Destination repo", "Packages" }); + for (const auto &a : actions) { + const LibRepoMgr::BuildActionTypeMetaInfo *typeInfo = nullptr; + if (meta.isTypeIdValid(a.type)) { + typeInfo = &meta.typeInfoForId(a.type); + } + const auto status = static_cast(a.status) < meta.states.size() ? meta.states[static_cast(a.status)].name : unknown; + const auto result + = static_cast(a.result) < meta.results.size() ? meta.results[static_cast(a.result)].name : unknown; + t.add_row({ numberToString(a.id), a.taskName, (typeInfo ? typeInfo->name : unknown).data(), status.data(), result.data(), + a.created.toString(DateTimeOutputFormat::DateAndTime, true), a.started.toString(DateTimeOutputFormat::DateAndTime, true), + (a.finished - a.started).toString(TimeSpanOutputFormat::WithMeasures, true), a.directory, joinStrings(a.sourceDbs, ", "), + joinStrings(a.destinationDbs, ", "), joinStrings(a.packageNames, ", ") }); + } + t.row(0).format().font_align(tabulate::FontAlign::center).font_style({ tabulate::FontStyle::bold }); + configureColumnWidths(t); + std::cout << t << std::endl; +} + void printRawData(const LibRepoMgr::WebClient::Response::body_type::value_type &rawData) { if (!rawData.empty()) { @@ -293,9 +322,14 @@ int main(int argc, const char *argv[]) path = "/api/v0/packages?mode=name&details=1&name=" + LibRepoMgr::WebAPI::Url::encodeValue(packageNameArg.values().front()); printer = printPackageDetails; }); + OperationArgument listActionsArg("list-actions", 'l', "list build actions"); + listActionsArg.setCallback([&path, &printer](const ArgumentOccurrence &) { + path = "/api/v0/build-action"; + printer = printListOfBuildActions; + }); HelpArgument helpArg(parser); NoColorArgument noColorArg; - parser.setMainArguments({ &searchArg, &packageArg, &instanceArg, &configFileArg, &noColorArg, &helpArg }); + parser.setMainArguments({ &searchArg, &packageArg, &listActionsArg, &instanceArg, &configFileArg, &noColorArg, &helpArg }); parser.parseArgs(argc, argv); // return early if no operation specified