lib/cli: rename renderX options to mkX

Mirrors the naming scheme in `generators.nix`, for consistency.

Also rename `key` to `k` and value to `v` to aid readability to the
code structure.
This commit is contained in:
Profpatsch 2020-01-22 23:55:42 +01:00
parent b2654c226a
commit e71e1be859

View File

@ -43,29 +43,26 @@ rec {
options: attrs: lib.escapeShellArgs (toGNUCommandLine options attrs); options: attrs: lib.escapeShellArgs (toGNUCommandLine options attrs);
toGNUCommandLine = toGNUCommandLine =
{ renderKey ? { mkKey ?
key: k: if builtins.stringLength k == 1
if builtins.stringLength key == 1 then "-${k}"
then "-${key}" else "--${k}"
else "--${key}"
, renderOption ? , mkOption ?
key: value: k: v: if v == null
if value == null then []
then [] else [ (mkKey k) (builtins.toString v) ]
else [ (renderKey key) (builtins.toString value) ]
, renderBool ? key: value: lib.optional value (renderKey key) , mkBool ? k: v: lib.optional v (mkKey k)
, renderList ? key: value: lib.concatMap (renderOption key) value , mkList ? k: v: lib.concatMap (mkOption k) v
}: }:
options: options:
let let
render = render = k: v:
key: value: if builtins.isBool v then mkBool k v
if builtins.isBool value then renderBool key value else if builtins.isList v then mkList k v
else if builtins.isList value then renderList key value else mkOption k v;
else renderOption key value;
in in
builtins.concatLists (lib.mapAttrsToList render options); builtins.concatLists (lib.mapAttrsToList render options);