lib/option-warnings: add mkRemovedOption (#209)

This commit is contained in:
Gaétan Lepage 2023-02-28 15:26:01 +01:00 committed by GitHub
parent 101b721f6f
commit c9abc97ee5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -69,14 +69,27 @@ with lib; rec {
overrideDescription = "Alias of ${showOption newOption}";
};
# TODO:
# mkRemovedOption =
# { option
# , visible ? false
# }:
# { options, ... }:
# {
# options = { };
# config = { };
# };
mkRemovedOption = {
option, # an array of the path to the option
alternative ? null,
message ? null,
visible ? false,
}: {
options,
config,
...
}: let
fromOpt = getAttrFromPath option options;
fromValue = getAttrFromPath option config;
fullMessage =
"The option `${showOption option}` has been removed."
+ (optionalString (alternative != null) " You may want to use `${showOption alternative}` instead.")
+ (optionalString (message != null) " Message: ${message}");
in {
config = mkIf (fromOpt.isDefined && fromValue != fromOpt.default) {
warnings = [
"Nixvim: ${fullMessage}"
];
};
};
}