nix store ping: try to print json if connect() fails aswell

This commit is contained in:
Yorick 2023-01-31 15:10:39 +01:00
parent 28648ed784
commit 4f4a6074e4
No known key found for this signature in database
GPG key ID: A36E70F9DC014A15

View file

@ -1,6 +1,7 @@
#include "command.hh" #include "command.hh"
#include "shared.hh" #include "shared.hh"
#include "store-api.hh" #include "store-api.hh"
#include "finally.hh"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@ -29,11 +30,13 @@ struct CmdPingStore : StoreCommand, MixJSON
notice("Version: %s", *version); notice("Version: %s", *version);
} else { } else {
nlohmann::json res; nlohmann::json res;
Finally printRes([&]() {
logger->cout("%s", res);
});
res["url"] = store->getUri(); res["url"] = store->getUri();
store->connect(); store->connect();
if (auto version = store->getVersion()) if (auto version = store->getVersion())
res["version"] = *version; res["version"] = *version;
logger->cout("%s", res);
} }
} }
}; };