mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 02:11:33 +00:00
Merge pull request #254 from horriblename/fix-bad-import
Add rename warnings for nvimTree.setupOpts.*
This commit is contained in:
commit
f3817fb4b2
2 changed files with 124 additions and 6 deletions
|
@ -1,6 +1,9 @@
|
|||
{lib}: let
|
||||
inherit (lib.options) mkOption;
|
||||
inherit (lib.types) bool;
|
||||
inherit (lib.modules) mkRenamedOptionModule;
|
||||
inherit (lib.attrsets) mapAttrsToList;
|
||||
inherit (lib.lists) flatten;
|
||||
in {
|
||||
mkBool = value: description:
|
||||
mkOption {
|
||||
|
@ -8,4 +11,55 @@ in {
|
|||
default = value;
|
||||
inherit description;
|
||||
};
|
||||
|
||||
/*
|
||||
Generates a list of mkRenamedOptionModule, from a mapping of the old name to
|
||||
the new name. Nested options can optionally supply a "_name" to indicate its
|
||||
new name.
|
||||
|
||||
# Example
|
||||
|
||||
```nix
|
||||
batchRenameOptions ["nvimTree"] ["nvimTree" "setupOpts"] {
|
||||
disableNetrw = "disable_netrw";
|
||||
nestedOption = {
|
||||
_name = "nested_option";
|
||||
somethingElse = "something_else";
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
The above code is equivalent to this:
|
||||
|
||||
```nix
|
||||
[
|
||||
(
|
||||
mkRenamedOptionModule
|
||||
["nvimTree" "disableNetrw"]
|
||||
["nvimTree" "setupOpts" "disable_netrw"]
|
||||
)
|
||||
(
|
||||
mkRenamedOptionModule
|
||||
["nvimTree" "nestedOption" "somethingElse"]
|
||||
["nvimTree" "setupOpts" "nested_option" "something_else"]
|
||||
)
|
||||
]
|
||||
```
|
||||
*/
|
||||
batchRenameOptions = oldBasePath: newBasePath: mappings: let
|
||||
genSetupOptRenames = oldSubpath: newSubpath: table:
|
||||
mapAttrsToList (
|
||||
oldName: newNameOrNestedOpts:
|
||||
if builtins.isAttrs newNameOrNestedOpts
|
||||
then
|
||||
genSetupOptRenames (oldSubpath ++ [oldName]) (newSubpath ++ [newNameOrNestedOpts._name or oldName])
|
||||
(builtins.removeAttrs newNameOrNestedOpts ["_name"])
|
||||
else
|
||||
mkRenamedOptionModule
|
||||
(oldBasePath ++ oldSubpath ++ [oldName])
|
||||
(newBasePath ++ newSubpath ++ [newNameOrNestedOpts])
|
||||
)
|
||||
table;
|
||||
in
|
||||
flatten (genSetupOptRenames [] [] mappings);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue