Merge pull request #276271 from hercules-ci/modules-types-description-nonRestrictiveClause
lib.types: Improve descriptions of composed types that have commas
This commit is contained in:
commit
9f98c59547
2 changed files with 31 additions and 3 deletions
|
@ -1959,6 +1959,18 @@ runTests {
|
||||||
expr = (with types; int).description;
|
expr = (with types; int).description;
|
||||||
expected = "signed integer";
|
expected = "signed integer";
|
||||||
};
|
};
|
||||||
|
testTypeDescriptionIntsPositive = {
|
||||||
|
expr = (with types; ints.positive).description;
|
||||||
|
expected = "positive integer, meaning >0";
|
||||||
|
};
|
||||||
|
testTypeDescriptionIntsPositiveOrEnumAuto = {
|
||||||
|
expr = (with types; either ints.positive (enum ["auto"])).description;
|
||||||
|
expected = ''positive integer, meaning >0, or value "auto" (singular enum)'';
|
||||||
|
};
|
||||||
|
testTypeDescriptionListOfPositive = {
|
||||||
|
expr = (with types; listOf ints.positive).description;
|
||||||
|
expected = "list of (positive integer, meaning >0)";
|
||||||
|
};
|
||||||
testTypeDescriptionListOfInt = {
|
testTypeDescriptionListOfInt = {
|
||||||
expr = (with types; listOf int).description;
|
expr = (with types; listOf int).description;
|
||||||
expected = "list of signed integer";
|
expected = "list of signed integer";
|
||||||
|
|
|
@ -113,9 +113,14 @@ rec {
|
||||||
, # Description of the type, defined recursively by embedding the wrapped type if any.
|
, # Description of the type, defined recursively by embedding the wrapped type if any.
|
||||||
description ? null
|
description ? null
|
||||||
# A hint for whether or not this description needs parentheses. Possible values:
|
# A hint for whether or not this description needs parentheses. Possible values:
|
||||||
# - "noun": a simple noun phrase such as "positive integer"
|
# - "noun": a noun phrase
|
||||||
# - "conjunction": a phrase with a potentially ambiguous "or" connective.
|
# Example description: "positive integer",
|
||||||
|
# - "conjunction": a phrase with a potentially ambiguous "or" connective
|
||||||
|
# Example description: "int or string"
|
||||||
# - "composite": a phrase with an "of" connective
|
# - "composite": a phrase with an "of" connective
|
||||||
|
# Example description: "list of string"
|
||||||
|
# - "nonRestrictiveClause": a noun followed by a comma and a clause
|
||||||
|
# Example description: "positive integer, meaning >0"
|
||||||
# See the `optionDescriptionPhrase` function.
|
# See the `optionDescriptionPhrase` function.
|
||||||
, descriptionClass ? null
|
, descriptionClass ? null
|
||||||
, # DO NOT USE WITHOUT KNOWING WHAT YOU ARE DOING!
|
, # DO NOT USE WITHOUT KNOWING WHAT YOU ARE DOING!
|
||||||
|
@ -338,10 +343,12 @@ rec {
|
||||||
unsigned = addCheck types.int (x: x >= 0) // {
|
unsigned = addCheck types.int (x: x >= 0) // {
|
||||||
name = "unsignedInt";
|
name = "unsignedInt";
|
||||||
description = "unsigned integer, meaning >=0";
|
description = "unsigned integer, meaning >=0";
|
||||||
|
descriptionClass = "nonRestrictiveClause";
|
||||||
};
|
};
|
||||||
positive = addCheck types.int (x: x > 0) // {
|
positive = addCheck types.int (x: x > 0) // {
|
||||||
name = "positiveInt";
|
name = "positiveInt";
|
||||||
description = "positive integer, meaning >0";
|
description = "positive integer, meaning >0";
|
||||||
|
descriptionClass = "nonRestrictiveClause";
|
||||||
};
|
};
|
||||||
u8 = unsign 8 256;
|
u8 = unsign 8 256;
|
||||||
u16 = unsign 16 65536;
|
u16 = unsign 16 65536;
|
||||||
|
@ -383,10 +390,12 @@ rec {
|
||||||
nonnegative = addCheck number (x: x >= 0) // {
|
nonnegative = addCheck number (x: x >= 0) // {
|
||||||
name = "numberNonnegative";
|
name = "numberNonnegative";
|
||||||
description = "nonnegative integer or floating point number, meaning >=0";
|
description = "nonnegative integer or floating point number, meaning >=0";
|
||||||
|
descriptionClass = "nonRestrictiveClause";
|
||||||
};
|
};
|
||||||
positive = addCheck number (x: x > 0) // {
|
positive = addCheck number (x: x > 0) // {
|
||||||
name = "numberPositive";
|
name = "numberPositive";
|
||||||
description = "positive integer or floating point number, meaning >0";
|
description = "positive integer or floating point number, meaning >0";
|
||||||
|
descriptionClass = "nonRestrictiveClause";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -463,6 +472,7 @@ rec {
|
||||||
passwdEntry = entryType: addCheck entryType (str: !(hasInfix ":" str || hasInfix "\n" str)) // {
|
passwdEntry = entryType: addCheck entryType (str: !(hasInfix ":" str || hasInfix "\n" str)) // {
|
||||||
name = "passwdEntry ${entryType.name}";
|
name = "passwdEntry ${entryType.name}";
|
||||||
description = "${optionDescriptionPhrase (class: class == "noun") entryType}, not containing newlines or colons";
|
description = "${optionDescriptionPhrase (class: class == "noun") entryType}, not containing newlines or colons";
|
||||||
|
descriptionClass = "nonRestrictiveClause";
|
||||||
};
|
};
|
||||||
|
|
||||||
attrs = mkOptionType {
|
attrs = mkOptionType {
|
||||||
|
@ -870,7 +880,13 @@ rec {
|
||||||
# Either value of type `t1` or `t2`.
|
# Either value of type `t1` or `t2`.
|
||||||
either = t1: t2: mkOptionType rec {
|
either = t1: t2: mkOptionType rec {
|
||||||
name = "either";
|
name = "either";
|
||||||
description = "${optionDescriptionPhrase (class: class == "noun" || class == "conjunction") t1} or ${optionDescriptionPhrase (class: class == "noun" || class == "conjunction" || class == "composite") t2}";
|
description =
|
||||||
|
if t1.descriptionClass or null == "nonRestrictiveClause"
|
||||||
|
then
|
||||||
|
# Plain, but add comma
|
||||||
|
"${t1.description}, or ${optionDescriptionPhrase (class: class == "noun" || class == "conjunction") t2}"
|
||||||
|
else
|
||||||
|
"${optionDescriptionPhrase (class: class == "noun" || class == "conjunction") t1} or ${optionDescriptionPhrase (class: class == "noun" || class == "conjunction" || class == "composite") t2}";
|
||||||
descriptionClass = "conjunction";
|
descriptionClass = "conjunction";
|
||||||
check = x: t1.check x || t2.check x;
|
check = x: t1.check x || t2.check x;
|
||||||
merge = loc: defs:
|
merge = loc: defs:
|
||||||
|
|
Loading…
Reference in a new issue