nix store ping: add --json flag

This commit is contained in:
Yorick 2023-01-31 13:24:23 +01:00
parent c79b1582a7
commit 28648ed784
No known key found for this signature in database
GPG key ID: A36E70F9DC014A15

View file

@ -2,9 +2,11 @@
#include "shared.hh"
#include "store-api.hh"
#include <nlohmann/json.hpp>
using namespace nix;
struct CmdPingStore : StoreCommand
struct CmdPingStore : StoreCommand, MixJSON
{
std::string description() override
{
@ -20,10 +22,19 @@ struct CmdPingStore : StoreCommand
void run(ref<Store> store) override
{
notice("Store URL: %s", store->getUri());
store->connect();
if (auto version = store->getVersion())
notice("Version: %s", *version);
if (!json) {
notice("Store URL: %s", store->getUri());
store->connect();
if (auto version = store->getVersion())
notice("Version: %s", *version);
} else {
nlohmann::json res;
res["url"] = store->getUri();
store->connect();
if (auto version = store->getVersion())
res["version"] = *version;
logger->cout("%s", res);
}
}
};