diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-08-24 13:11:56 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-08-24 13:16:02 +0200 |
commit | 33b1679d75f2a3a5dac053431a41897ebf96a3f3 (patch) | |
tree | 879d2bb748c7d2bc4c6daf8ffa49c604dd265e6d /src/nix/repl.cc | |
parent | 88d5c9ec584f000c9a66ad34631fe4eb5c194172 (diff) |
Allow primops to have Markdown documentation
Diffstat (limited to 'src/nix/repl.cc')
-rw-r--r-- | src/nix/repl.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 0cbe9643c..d370ca767 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -416,7 +416,8 @@ bool NixRepl::processLine(string line) << " :r Reload all files\n" << " :s <expr> Build dependencies of derivation, then start nix-shell\n" << " :t <expr> Describe result of evaluation\n" - << " :u <expr> Build derivation, then start nix-shell\n"; + << " :u <expr> Build derivation, then start nix-shell\n" + << " :doc <expr> Show documentation of a builtin function\n"; } else if (command == ":a" || command == ":add") { @@ -509,6 +510,24 @@ bool NixRepl::processLine(string line) else if (command == ":q" || command == ":quit") return false; + else if (command == ":doc") { + Value v; + evalString(arg, v); + if (v.type == tPrimOp || v.type == tPrimOpApp) { + auto v2 = &v; + while (v2->type == tPrimOpApp) + v2 = v2->primOpApp.left; + if (v2->primOp->doc) { + // FIXME: format markdown. + if (!v2->primOp->args.empty()) + std::cout << fmt("Arguments: %s\n\n", concatStringsSep(" ", v2->primOp->args)); + std::cout << trim(stripIndentation(v2->primOp->doc)) << "\n"; + } else + throw Error("builtin function '%s' does not have documentation", v2->primOp->name); + } else + throw Error("value does not have documentation"); + } + else if (command != "") throw Error("unknown command '%1%'", command); |