mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 11:39:46 +01:00
lf: simplify option validation (#4334)
Don't try to validate a limited set of hardcoded options, instead just convert them as-is. Now, users can keep all their options in a single attribute set, including arbitrary `user_{option}`s which was impossible to express with a hard-coded submodule. As a plus, there is also less maintainence burden.
This commit is contained in:
parent
255f921049
commit
406d34d919
2 changed files with 13 additions and 67 deletions
|
@ -2,55 +2,7 @@
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let cfg = config.programs.lf;
|
||||||
cfg = config.programs.lf;
|
|
||||||
|
|
||||||
knownSettings = {
|
|
||||||
anchorfind = types.bool;
|
|
||||||
color256 = types.bool;
|
|
||||||
dircounts = types.bool;
|
|
||||||
dirfirst = types.bool;
|
|
||||||
drawbox = types.bool;
|
|
||||||
globsearch = types.bool;
|
|
||||||
icons = types.bool;
|
|
||||||
hidden = types.bool;
|
|
||||||
ignorecase = types.bool;
|
|
||||||
ignoredia = types.bool;
|
|
||||||
incsearch = types.bool;
|
|
||||||
preview = types.bool;
|
|
||||||
reverse = types.bool;
|
|
||||||
smartcase = types.bool;
|
|
||||||
smartdia = types.bool;
|
|
||||||
wrapscan = types.bool;
|
|
||||||
wrapscroll = types.bool;
|
|
||||||
number = types.bool;
|
|
||||||
relativenumber = types.bool;
|
|
||||||
findlen = types.int;
|
|
||||||
period = types.int;
|
|
||||||
scrolloff = types.int;
|
|
||||||
tabstop = types.int;
|
|
||||||
errorfmt = types.str;
|
|
||||||
filesep = types.str;
|
|
||||||
ifs = types.str;
|
|
||||||
promptfmt = types.str;
|
|
||||||
shell = types.str;
|
|
||||||
sortby = types.str;
|
|
||||||
timefmt = types.str;
|
|
||||||
ratios = types.str;
|
|
||||||
info = types.str;
|
|
||||||
shellopts = types.str;
|
|
||||||
};
|
|
||||||
|
|
||||||
lfSettingsType = types.submodule {
|
|
||||||
options = let
|
|
||||||
opt = name: type:
|
|
||||||
mkOption {
|
|
||||||
type = types.nullOr type;
|
|
||||||
default = null;
|
|
||||||
visible = false;
|
|
||||||
};
|
|
||||||
in mapAttrs opt knownSettings;
|
|
||||||
};
|
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [ hm.maintainers.owm111 ];
|
meta.maintainers = [ hm.maintainers.owm111 ];
|
||||||
|
|
||||||
|
@ -68,27 +20,19 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
settings = mkOption {
|
settings = mkOption {
|
||||||
type = lfSettingsType;
|
type = with types;
|
||||||
|
attrsOf (oneOf [ str int (listOf (either str int)) bool ]);
|
||||||
default = { };
|
default = { };
|
||||||
example = {
|
example = {
|
||||||
tabstop = 4;
|
tabstop = 4;
|
||||||
number = true;
|
number = true;
|
||||||
ratios = "1:1:2";
|
ratios = [ 1 1 2 ];
|
||||||
};
|
};
|
||||||
description = ''
|
description = ''
|
||||||
An attribute set of lf settings. The attribute names and corresponding
|
An attribute set of lf settings. See the lf documentation for
|
||||||
values must be among the following supported options.
|
detailed descriptions of these options. Prefer
|
||||||
|
{option}`programs.lf.previewer.*` for setting lf's {var}`previewer`
|
||||||
${concatStringsSep "\n" (mapAttrsToList (n: v: ''
|
option. All string options are quoted with double quotes.
|
||||||
{var}`${n}`
|
|
||||||
: ${v.description}
|
|
||||||
'') knownSettings)}
|
|
||||||
|
|
||||||
See the lf documentation for detailed descriptions of these options.
|
|
||||||
Use {option}`programs.lf.previewer.*` to set lf's
|
|
||||||
{var}`previewer` option, and
|
|
||||||
[](#opt-programs.lf.extraConfig) for any other option not listed above.
|
|
||||||
All string options are quoted with double quotes.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -181,12 +125,14 @@ in {
|
||||||
optionalString (v != null) "set ${
|
optionalString (v != null) "set ${
|
||||||
if isBool v then
|
if isBool v then
|
||||||
"${optionalString (!v) "no"}${k}"
|
"${optionalString (!v) "no"}${k}"
|
||||||
|
else if isList v then
|
||||||
|
''${k} "${concatStringsSep ":" (map (w: toString w) v)}"''
|
||||||
else
|
else
|
||||||
"${k} ${if isInt v then toString v else ''"${v}"''}"
|
"${k} ${if isInt v then toString v else ''"${v}"''}"
|
||||||
}";
|
}";
|
||||||
|
|
||||||
settingsStr = concatStringsSep "\n" (remove "" (mapAttrsToList fmtSetting
|
settingsStr = concatStringsSep "\n"
|
||||||
(builtins.intersectAttrs knownSettings cfg.settings)));
|
(remove "" (mapAttrsToList fmtSetting cfg.settings));
|
||||||
|
|
||||||
fmtCmdMap = before: k: v:
|
fmtCmdMap = before: k: v:
|
||||||
"${before} ${k}${optionalString (v != null && v != "") " ${v}"}";
|
"${before} ${k}${optionalString (v != null && v != "") " ${v}"}";
|
||||||
|
|
|
@ -71,7 +71,7 @@ in {
|
||||||
ignorecase = false;
|
ignorecase = false;
|
||||||
icons = true;
|
icons = true;
|
||||||
tabstop = 4;
|
tabstop = 4;
|
||||||
ratios = "2:2:3";
|
ratios = [ 2 2 3 ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue