diff options
author | Profpatsch <mail@profpatsch.de> | 2017-06-12 07:07:59 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2017-06-22 00:58:59 +0200 |
commit | 5cbc6ca9bb63f939dab2c2c82a63d72f1f30d9b7 (patch) | |
tree | 3e80385ca7d970dfca11cafe12be51e6ec0f08ec /lib/generators.nix | |
parent | feb8cbdc38c6b10b2c66a96151d8d560e960c29f (diff) | |
download | nixpkgs-5cbc6ca9bb63f939dab2c2c82a63d72f1f30d9b7.tar nixpkgs-5cbc6ca9bb63f939dab2c2c82a63d72f1f30d9b7.tar.gz nixpkgs-5cbc6ca9bb63f939dab2c2c82a63d72f1f30d9b7.tar.bz2 nixpkgs-5cbc6ca9bb63f939dab2c2c82a63d72f1f30d9b7.tar.lz nixpkgs-5cbc6ca9bb63f939dab2c2c82a63d72f1f30d9b7.tar.xz nixpkgs-5cbc6ca9bb63f939dab2c2c82a63d72f1f30d9b7.tar.zst nixpkgs-5cbc6ca9bb63f939dab2c2c82a63d72f1f30d9b7.zip |
lib/generators: put more information in toPretty lambdas
With `builtins.functionArgs` we can get some information if the first argument is an attrset and whether the contained fields have default values. Encode that into the pretty-printed lambda.
Diffstat (limited to 'lib/generators.nix')
-rw-r--r-- | lib/generators.nix | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/generators.nix b/lib/generators.nix index 0e5ce864356..4419c3c8891 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -91,7 +91,6 @@ rec { */ toYAML = {}@args: toJSON args; - # TODO we need some kind of pattern matching sometimes /* Pretty print a value, akin to `builtins.trace`. * Should probably be a builtin as well. */ @@ -105,7 +104,13 @@ rec { else if isBool v then (if v == true then "true" else "false") else if isString v then "\"" + v + "\"" else if null == v then "null" - else if isFunction v then "<λ>" + else if isFunction v then + let fna = functionArgs v; + showFnas = concatStringsSep "," (libAttr.mapAttrsToList + (name: hasDefVal: if hasDefVal then "(${name})" else name) + fna); + in if fna == {} then "<λ>" + else "<λ:{${showFnas}}>" else if isList v then "[ " + libStr.concatMapStringsSep " " (toPretty args) v + " ]" |