lib/cli: mkKey -> mkOptionName, use generators.mkValueStringDefault
Let’s call them by what they are, option names. `generators.mkValueStringDefault` is a better value string renderer than plain `toString`. Also add docs to all options.
This commit is contained in:
parent
18520b7f36
commit
7228a3c0bc
36
lib/cli.nix
36
lib/cli.nix
@ -42,20 +42,34 @@ rec {
|
|||||||
toGNUCommandLineShell =
|
toGNUCommandLineShell =
|
||||||
options: attrs: lib.escapeShellArgs (toGNUCommandLine options attrs);
|
options: attrs: lib.escapeShellArgs (toGNUCommandLine options attrs);
|
||||||
|
|
||||||
toGNUCommandLine =
|
toGNUCommandLine = {
|
||||||
{ mkKey ?
|
# how to string-format the option name;
|
||||||
k: if builtins.stringLength k == 1
|
# by default one character is a short option (`-`),
|
||||||
then "-${k}"
|
# more than one characters a long option (`--`).
|
||||||
else "--${k}"
|
mkOptionName ?
|
||||||
|
k: if builtins.stringLength k == 1
|
||||||
|
then "-${k}"
|
||||||
|
else "--${k}",
|
||||||
|
|
||||||
, mkOption ?
|
# how to format a boolean value to a command list;
|
||||||
k: v: if v == null
|
# by default it’s a flag option
|
||||||
then []
|
# (only the option name if true, left out completely if false).
|
||||||
else [ (mkKey k) (builtins.toString v) ]
|
mkBool ? k: v: lib.optional v (mkOptionName k),
|
||||||
|
|
||||||
, mkBool ? k: v: lib.optional v (mkKey k)
|
# how to format a list value to a command list;
|
||||||
|
# by default the option name is repeated for each value
|
||||||
|
# and `mkOption` is applied to the values themselves.
|
||||||
|
mkList ? k: v: lib.concatMap (mkOption k) v,
|
||||||
|
|
||||||
, mkList ? k: v: lib.concatMap (mkOption k) v
|
# how to format any remaining value to a command list;
|
||||||
|
# on the toplevel, booleans and lists are handled by `mkBool` and `mkList`,
|
||||||
|
# though they can still appear as values of a list.
|
||||||
|
# By default, everything is printed verbatim and complex types
|
||||||
|
# are forbidden (lists, attrsets, functions). `null` values are omitted.
|
||||||
|
mkOption ?
|
||||||
|
k: v: if v == null
|
||||||
|
then []
|
||||||
|
else [ (mkOptionName k) (lib.generators.mkValueStringDefault {} v) ]
|
||||||
}:
|
}:
|
||||||
options:
|
options:
|
||||||
let
|
let
|
||||||
|
Loading…
Reference in New Issue
Block a user