diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-09-16 17:02:30 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-09-16 17:02:30 +0200 |
commit | 5080d4e7b2525d1656282c65a217a22ff8381df3 (patch) | |
tree | 72eab8c0135ca5c37e1d9b099f7880ccfbe2401f /src/nix/describe-stores.cc | |
parent | 0066ef6c59c356d5714f2e26af9471937ba0c865 (diff) | |
parent | 77a0e2c5beba478f4cfc9f3c9516e516a5da43c9 (diff) |
Merge branch 'document-store-options' of https://github.com/tweag/nix
Diffstat (limited to 'src/nix/describe-stores.cc')
-rw-r--r-- | src/nix/describe-stores.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/nix/describe-stores.cc b/src/nix/describe-stores.cc new file mode 100644 index 000000000..0cc2d9337 --- /dev/null +++ b/src/nix/describe-stores.cc @@ -0,0 +1,44 @@ +#include "command.hh" +#include "common-args.hh" +#include "shared.hh" +#include "store-api.hh" + +#include <nlohmann/json.hpp> + +using namespace nix; + +struct CmdDescribeStores : Command, MixJSON +{ + std::string description() override + { + return "show registered store types and their available options"; + } + + Category category() override { return catUtility; } + + void run() override + { + auto res = nlohmann::json::object(); + for (auto & implem : *Implementations::registered) { + auto storeConfig = implem.getConfig(); + auto storeName = storeConfig->name(); + res[storeName] = storeConfig->toJSON(); + } + if (json) { + std::cout << res; + } else { + for (auto & [storeName, storeConfig] : res.items()) { + std::cout << "## " << storeName << std::endl << std::endl; + for (auto & [optionName, optionDesc] : storeConfig.items()) { + std::cout << "### " << optionName << std::endl << std::endl; + std::cout << optionDesc["description"].get<std::string>() << std::endl; + std::cout << "default: " << optionDesc["defaultValue"] << std::endl <<std::endl; + if (!optionDesc["aliases"].empty()) + std::cout << "aliases: " << optionDesc["aliases"] << std::endl << std::endl; + } + } + } + } +}; + +static auto r1 = registerCommand<CmdDescribeStores>("describe-stores"); |