forked from lix-project/lix
Generate builtins section of the manual
This commit is contained in:
parent
a990f063ff
commit
0f314f3c25
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -27,8 +27,10 @@ perl/Makefile.config
|
||||||
/doc/manual/*.8
|
/doc/manual/*.8
|
||||||
/doc/manual/nix.json
|
/doc/manual/nix.json
|
||||||
/doc/manual/conf-file.json
|
/doc/manual/conf-file.json
|
||||||
|
/doc/manual/builtins.json
|
||||||
/doc/manual/src/command-ref/nix.md
|
/doc/manual/src/command-ref/nix.md
|
||||||
/doc/manual/src/command-ref/conf-file.md
|
/doc/manual/src/command-ref/conf-file.md
|
||||||
|
/doc/manual/src/expressions/builtins.md
|
||||||
|
|
||||||
# /scripts/
|
# /scripts/
|
||||||
/scripts/nix-profile.sh
|
/scripts/nix-profile.sh
|
||||||
|
|
6
doc/manual/generate-builtins.jq
Normal file
6
doc/manual/generate-builtins.jq
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
. | to_entries | sort_by(.key) | map(
|
||||||
|
" - `builtins." + .key + "` "
|
||||||
|
+ (.value.args | map("*" + . + "*") | join(" "))
|
||||||
|
+ " \n\n"
|
||||||
|
+ (.value.doc | split("\n") | map(" " + . + "\n") | join("")) + "\n\n"
|
||||||
|
) | join("")
|
|
@ -32,15 +32,22 @@ $(d)/src/command-ref/conf-file.md: $(d)/conf-file.json $(d)/generate-options.jq
|
||||||
jq -r -f doc/manual/generate-options.jq $< >> $@
|
jq -r -f doc/manual/generate-options.jq $< >> $@
|
||||||
|
|
||||||
$(d)/nix.json: $(bindir)/nix
|
$(d)/nix.json: $(bindir)/nix
|
||||||
$(trace-gen) $(bindir)/nix dump-args > $@
|
$(trace-gen) $(bindir)/nix __dump-args > $@
|
||||||
|
|
||||||
$(d)/conf-file.json: $(bindir)/nix
|
$(d)/conf-file.json: $(bindir)/nix
|
||||||
$(trace-gen) env -i NIX_CONF_DIR=/dummy HOME=/dummy $(bindir)/nix show-config --json --experimental-features nix-command > $@
|
$(trace-gen) env -i NIX_CONF_DIR=/dummy HOME=/dummy $(bindir)/nix show-config --json --experimental-features nix-command > $@
|
||||||
|
|
||||||
|
$(d)/src/expressions/builtins.md: $(d)/builtins.json $(d)/generate-builtins.jq $(d)/src/expressions/builtins-prefix.md
|
||||||
|
cat doc/manual/src/expressions/builtins-prefix.md > $@
|
||||||
|
jq -r -f doc/manual/generate-builtins.jq $< >> $@
|
||||||
|
|
||||||
|
$(d)/builtins.json: $(bindir)/nix
|
||||||
|
$(trace-gen) $(bindir)/nix __dump-builtins > $@
|
||||||
|
|
||||||
# Generate the HTML manual.
|
# Generate the HTML manual.
|
||||||
install: $(docdir)/manual/index.html
|
install: $(docdir)/manual/index.html
|
||||||
|
|
||||||
$(docdir)/manual/index.html: $(MANUAL_SRCS) $(d)/book.toml $(d)/custom.css
|
$(docdir)/manual/index.html: $(MANUAL_SRCS) $(d)/book.toml $(d)/custom.css $(d)/src/command-ref/nix.md $(d)/src/command-ref/conf-file.md $(d)/src/expressions/builtins.md
|
||||||
$(trace-gen) mdbook build doc/manual -d $(docdir)/manual
|
$(trace-gen) mdbook build doc/manual -d $(docdir)/manual
|
||||||
@cp doc/manual/highlight.pack.js $(docdir)/manual/highlight.js
|
@cp doc/manual/highlight.pack.js $(docdir)/manual/highlight.js
|
||||||
|
|
||||||
|
|
|
@ -179,11 +179,29 @@ void mainWrapped(int argc, char * * argv)
|
||||||
|
|
||||||
NixArgs args;
|
NixArgs args;
|
||||||
|
|
||||||
if (argc == 2 && std::string(argv[1]) == "dump-args") {
|
if (argc == 2 && std::string(argv[1]) == "__dump-args") {
|
||||||
std::cout << args.toJSON().dump() << "\n";
|
std::cout << args.toJSON().dump() << "\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc == 2 && std::string(argv[1]) == "__dump-builtins") {
|
||||||
|
EvalState state({}, openStore("ssh://foo.invalid/"));
|
||||||
|
auto res = nlohmann::json::object();
|
||||||
|
auto builtins = state.baseEnv.values[0]->attrs;
|
||||||
|
for (auto & builtin : *builtins) {
|
||||||
|
auto b = nlohmann::json::object();
|
||||||
|
if (builtin.value->type != tPrimOp) continue;
|
||||||
|
auto primOp = builtin.value->primOp;
|
||||||
|
if (!primOp->doc) continue;
|
||||||
|
b["arity"] = primOp->arity;
|
||||||
|
b["args"] = primOp->args;
|
||||||
|
b["doc"] = trim(stripIndentation(primOp->doc));
|
||||||
|
res[(std::string) builtin.name] = std::move(b);
|
||||||
|
}
|
||||||
|
std::cout << res.dump() << "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Finally printCompletions([&]()
|
Finally printCompletions([&]()
|
||||||
{
|
{
|
||||||
if (completions) {
|
if (completions) {
|
||||||
|
|
Loading…
Reference in a new issue