lib/options: Introduce showDefs
For pretty-printing definitions, including file and values
This commit is contained in:
parent
2ff7c3e2e1
commit
7c20e68f6b
1 changed files with 18 additions and 0 deletions
|
@ -213,6 +213,24 @@ rec {
|
|||
else escaped;
|
||||
in (concatStringsSep ".") (map escapeOptionPart parts);
|
||||
showFiles = files: concatStringsSep " and " (map (f: "`${f}'") files);
|
||||
|
||||
showDefs = defs: concatMapStrings (def:
|
||||
let
|
||||
# Pretty print the value for display, if successful
|
||||
prettyEval = builtins.tryEval (lib.generators.toPretty {} def.value);
|
||||
# Split it into its lines
|
||||
lines = filter (v: ! isList v) (builtins.split "\n" prettyEval.value);
|
||||
# Only display the first 5 lines, and indent them for better visibility
|
||||
value = concatStringsSep "\n " (take 5 lines ++ optional (length lines > 5) "...");
|
||||
result =
|
||||
# Don't print any value if evaluating the value strictly fails
|
||||
if ! prettyEval.success then ""
|
||||
# Put it on a new line if it consists of multiple
|
||||
else if length lines > 1 then ":\n " + value
|
||||
else ": " + value;
|
||||
in "\n- In `${def.file}'${result}"
|
||||
) defs;
|
||||
|
||||
unknownModule = "<unknown-file>";
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue