Merge pull request #124353 from hercules-ci/small-enum-description

lib.types.enum: Improve description for lengths 0 and 1
This commit is contained in:
Robert Hensing 2021-07-18 19:08:49 +02:00 committed by GitHub
commit 6d29becbd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -581,7 +581,17 @@ rec {
in
mkOptionType rec {
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;
merge = mergeEqualOption;
functor = (defaultFunctor name) // { payload = values; binOp = a: b: unique (a ++ b); };