lib/options: use code-block for multiline defaults

Detect whether a plugin default is multiline using `hasInfix "\n"`.

Also remove `multiline=false` from the `toPretty` call.
This commit is contained in:
Matt Sturgeon 2024-05-28 22:16:32 +01:00
parent 9b340f8bab
commit cedc1e4799
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299

View file

@ -64,12 +64,13 @@ rec {
# Assume a string default is already formatted as intended, # Assume a string default is already formatted as intended,
# historically strings were the only type accepted here. # historically strings were the only type accepted here.
# TODO consider deprecating this behavior so we can properly quote strings # TODO consider deprecating this behavior so we can properly quote strings
if isString defaultValue then if isString defaultValue then defaultValue else generators.toPretty { } defaultValue;
defaultValue
else
generators.toPretty { multiline = false; } defaultValue;
in in
"Plugin default: `${default}`"; "Plugin default:"
+ (
# Detect whether `default` is multiline or inline:
if hasInfix "\n" default then "\n\n```nix\n${default}\n```" else " `${default}`"
);
mkDesc = mkDesc =
default: desc: default: desc: