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.
This commit is contained in:
parent
feb8cbdc38
commit
5cbc6ca9bb
@ -91,7 +91,6 @@ rec {
|
|||||||
*/
|
*/
|
||||||
toYAML = {}@args: toJSON args;
|
toYAML = {}@args: toJSON args;
|
||||||
|
|
||||||
# TODO we need some kind of pattern matching sometimes
|
|
||||||
/* Pretty print a value, akin to `builtins.trace`.
|
/* Pretty print a value, akin to `builtins.trace`.
|
||||||
* Should probably be a builtin as well.
|
* 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 isBool v then (if v == true then "true" else "false")
|
||||||
else if isString v then "\"" + v + "\""
|
else if isString v then "\"" + v + "\""
|
||||||
else if null == v then "null"
|
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 "[ "
|
else if isList v then "[ "
|
||||||
+ libStr.concatMapStringsSep " " (toPretty args) v
|
+ libStr.concatMapStringsSep " " (toPretty args) v
|
||||||
+ " ]"
|
+ " ]"
|
||||||
|
@ -292,6 +292,7 @@ runTests {
|
|||||||
string = "fnord";
|
string = "fnord";
|
||||||
null_ = null;
|
null_ = null;
|
||||||
function = x: x;
|
function = x: x;
|
||||||
|
functionArgs = { arg ? 4, foo }: arg;
|
||||||
list = [ 3 4 function [ false ] ];
|
list = [ 3 4 function [ false ] ];
|
||||||
attrs = { foo = null; "foo bar" = "baz"; };
|
attrs = { foo = null; "foo bar" = "baz"; };
|
||||||
drv = derivation { name = "test"; system = builtins.currentSystem; };
|
drv = derivation { name = "test"; system = builtins.currentSystem; };
|
||||||
@ -302,6 +303,7 @@ runTests {
|
|||||||
string = "\"fnord\"";
|
string = "\"fnord\"";
|
||||||
null_ = "null";
|
null_ = "null";
|
||||||
function = "<λ>";
|
function = "<λ>";
|
||||||
|
functionArgs = "<λ:{(arg),foo}>";
|
||||||
list = "[ 3 4 ${function} [ false ] ]";
|
list = "[ 3 4 ${function} [ false ] ]";
|
||||||
attrs = "{ \"foo\" = null; \"foo bar\" = \"baz\"; }";
|
attrs = "{ \"foo\" = null; \"foo bar\" = \"baz\"; }";
|
||||||
drv = "<δ>";
|
drv = "<δ>";
|
||||||
|
Loading…
Reference in New Issue
Block a user