From 5cbc6ca9bb63f939dab2c2c82a63d72f1f30d9b7 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Mon, 12 Jun 2017 07:07:59 +0200 Subject: 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. --- lib/generators.nix | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/generators.nix') diff --git a/lib/generators.nix b/lib/generators.nix index 0e5ce864356a..4419c3c88917 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 + " ]" -- cgit 1.4.1