mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-24 17:58:38 +02:00
helpers: Add option helpers for types that are either a lua str or a value (#876)
Those types needed the following code in apply: if builtins.isString value then mkRaw value else value This commit avoids this boilerplate, and clarifies that the `str` is lua code in the documentation.
This commit is contained in:
parent
8b8a1c0f4b
commit
8aa4b7e4ce
13 changed files with 109 additions and 129 deletions
|
@ -95,6 +95,28 @@ with lib; rec {
|
|||
apply = mkRaw;
|
||||
};
|
||||
|
||||
mkNullOrStrLuaOr = ty: desc:
|
||||
lib.mkOption {
|
||||
type = lib.types.nullOr (types.either nixvimTypes.strLua ty);
|
||||
default = null;
|
||||
description = desc;
|
||||
apply = v:
|
||||
if builtins.isString v
|
||||
then mkRaw v
|
||||
else v;
|
||||
};
|
||||
|
||||
mkNullOrStrLuaFnOr = ty: desc:
|
||||
lib.mkOption {
|
||||
type = lib.types.nullOr (types.either nixvimTypes.strLuaFn ty);
|
||||
default = null;
|
||||
description = desc;
|
||||
apply = v:
|
||||
if builtins.isString v
|
||||
then mkRaw v
|
||||
else v;
|
||||
};
|
||||
|
||||
defaultNullOpts = let
|
||||
maybeRaw = t: lib.types.either t nixvimTypes.rawLua;
|
||||
in rec {
|
||||
|
@ -116,6 +138,30 @@ with lib; rec {
|
|||
# documentation
|
||||
mkNullableWithRaw = type: mkNullable (maybeRaw type);
|
||||
|
||||
mkStrLuaOr = type: default: desc:
|
||||
mkNullOrStrLuaOr type (let
|
||||
defaultDesc = "default: `${default}`";
|
||||
in
|
||||
if desc == ""
|
||||
then defaultDesc
|
||||
else ''
|
||||
${desc}
|
||||
|
||||
${defaultDesc}
|
||||
'');
|
||||
|
||||
mkStrLuaFnOr = type: default: desc:
|
||||
mkNullOrStrLuaFnOr type (let
|
||||
defaultDesc = "default: `${default}`";
|
||||
in
|
||||
if desc == ""
|
||||
then defaultDesc
|
||||
else ''
|
||||
${desc}
|
||||
|
||||
${defaultDesc}
|
||||
'');
|
||||
|
||||
mkLua = default: desc:
|
||||
mkNullOrLua
|
||||
(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue