1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 06:01:48 +02:00

nix store --help: Include store type documentation

This commit is contained in:
Eelco Dolstra 2023-03-21 12:58:14 +01:00
parent cdfa59daa1
commit 8d6d59cb1b
9 changed files with 102 additions and 60 deletions

View file

@ -12,7 +12,7 @@ struct HttpBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
{
using BinaryCacheStoreConfig::BinaryCacheStoreConfig;
const std::string name() override { return "Http Binary Cache Store"; }
const std::string name() override { return "HTTP Binary Cache Store"; }
};
class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public virtual BinaryCacheStore

View file

@ -22,7 +22,7 @@ struct CmdDescribeStores : Command, MixJSON
for (auto & implem : *Implementations::registered) {
auto storeConfig = implem.getConfig();
auto storeName = storeConfig->name();
res[storeName] = storeConfig->toJSON();
res[storeName]["settings"] = storeConfig->toJSON();
}
if (json) {
logger->cout("%s", res);

View file

@ -164,11 +164,28 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
{
commands = RegisterCommand::getCommandsFor({});
}
std::string dumpCli()
{
auto res = nlohmann::json::object();
res["args"] = toJSON();
auto stores = nlohmann::json::object();
for (auto & implem : *Implementations::registered) {
auto storeConfig = implem.getConfig();
auto storeName = storeConfig->name();
stores[storeName]["settings"] = storeConfig->toJSON();
}
res["stores"] = std::move(stores);
return res.dump();
}
};
/* Render the help for the specified subcommand to stdout using
lowdown. */
static void showHelp(std::vector<std::string> subcommand, MultiCommand & toplevel)
static void showHelp(std::vector<std::string> subcommand, NixArgs & toplevel)
{
auto mdName = subcommand.empty() ? "nix" : fmt("nix3-%s", concatStringsSep("-", subcommand));
@ -189,11 +206,11 @@ static void showHelp(std::vector<std::string> subcommand, MultiCommand & topleve
, "/"),
*vUtils);
auto attrs = state.buildBindings(16);
attrs.alloc("toplevel").mkString(toplevel.toJSON().dump());
auto vDump = state.allocValue();
vDump->mkString(toplevel.dumpCli());
auto vRes = state.allocValue();
state.callFunction(*vGenerateManpage, state.allocValue()->mkAttrs(attrs), *vRes, noPos);
state.callFunction(*vGenerateManpage, *vDump, *vRes, noPos);
auto attr = vRes->attrs->get(state.symbols.create(mdName + ".md"));
if (!attr)
@ -234,7 +251,7 @@ struct CmdHelp : Command
assert(parent);
MultiCommand * toplevel = parent;
while (toplevel->parent) toplevel = toplevel->parent;
showHelp(subcommand, *toplevel);
showHelp(subcommand, dynamic_cast<NixArgs &>(*toplevel));
}
};
@ -291,8 +308,8 @@ void mainWrapped(int argc, char * * argv)
NixArgs args;
if (argc == 2 && std::string(argv[1]) == "__dump-args") {
logger->cout("%s", args.toJSON());
if (argc == 2 && std::string(argv[1]) == "__dump-cli") {
logger->cout(args.dumpCli());
return;
}

View file

@ -12,6 +12,13 @@ struct CmdStore : virtual NixMultiCommand
return "manipulate a Nix store";
}
std::string doc() override
{
return
#include "store.md"
;
}
Category category() override { return catUtility; }
void run() override

9
src/nix/store.md Normal file
View file

@ -0,0 +1,9 @@
R"(
# Store types
Nix supports different types of stores. These are listed below.
@stores@
)"