diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2023-02-01 17:11:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-01 17:11:34 +0100 |
commit | 7a09bfbcb631b7dfb56d4c04687bc0f6e3e39f75 (patch) | |
tree | 9bcee7988cda87ce0235638bd3074f812e7d2e4c /src | |
parent | 518da6c6a30881bd0e767a84c8193a198eeed230 (diff) | |
parent | 4757b3f04e0a4568ab40ab86b9251945874a5662 (diff) |
Merge pull request #7723 from yorickvP/nix-store-ping-json
nix store ping: add --json flag
Diffstat (limited to 'src')
-rw-r--r-- | src/nix/ping-store.cc | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/nix/ping-store.cc b/src/nix/ping-store.cc index 3c3b7bb45..5c44510ab 100644 --- a/src/nix/ping-store.cc +++ b/src/nix/ping-store.cc @@ -1,10 +1,13 @@ #include "command.hh" #include "shared.hh" #include "store-api.hh" +#include "finally.hh" + +#include <nlohmann/json.hpp> using namespace nix; -struct CmdPingStore : StoreCommand +struct CmdPingStore : StoreCommand, MixJSON { std::string description() override { @@ -20,10 +23,21 @@ 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; + Finally printRes([&]() { + logger->cout("%s", res); + }); + res["url"] = store->getUri(); + store->connect(); + if (auto version = store->getVersion()) + res["version"] = *version; + } } }; |