lib.types.enum: Improve description for lengths 0 and 1
This commit is contained in:
parent
9ae7b7e706
commit
285632320d
@ -581,7 +581,17 @@ rec {
|
|||||||
in
|
in
|
||||||
mkOptionType rec {
|
mkOptionType rec {
|
||||||
name = "enum";
|
name = "enum";
|
||||||
description = "one of ${concatMapStringsSep ", " show values}";
|
description =
|
||||||
|
# Length 0 or 1 enums may occur in a design pattern with type merging
|
||||||
|
# where an "interface" module declares an empty enum and other modules
|
||||||
|
# provide implementations, each extending the enum with their own
|
||||||
|
# identifier.
|
||||||
|
if values == [] then
|
||||||
|
"impossible (empty enum)"
|
||||||
|
else if builtins.length values == 1 then
|
||||||
|
"value ${show (builtins.head values)} (singular enum)"
|
||||||
|
else
|
||||||
|
"one of ${concatMapStringsSep ", " show values}";
|
||||||
check = flip elem values;
|
check = flip elem values;
|
||||||
merge = mergeEqualOption;
|
merge = mergeEqualOption;
|
||||||
functor = (defaultFunctor name) // { payload = values; binOp = a: b: unique (a ++ b); };
|
functor = (defaultFunctor name) // { payload = values; binOp = a: b: unique (a ++ b); };
|
||||||
|
Loading…
Reference in New Issue
Block a user