toCommandLineGNU
lib.cli.toCommandLineGNU
Docs pulled from | This Revision | 4 days ago
Converts an attribute set into a list of GNU-style command line options.
toCommandLineGNU returns a list of string arguments.
Inputs
options-
Options, see below.
attrs-
The attributes to transform into arguments.
Options
isLong-
A function that determines whether an option is long or short.
explicitBool-
Whether or not boolean option arguments should be formatted explicitly.
formatArg-
A function that turns the option argument into a string.
Examples
lib.cli.toCommandLineGNU usage example
lib.cli.toCommandLineGNU {} {
v = true;
verbose = [true true false null];
i = ".bak";
testsuite = ["unit" "integration"];
e = ["s/a/b/" "s/b/c/"];
n = false;
data = builtins.toJSON {id = 0;};
}
=> [
"--data={\"id\":0}"
"-es/a/b/"
"-es/b/c/"
"-i.bak"
"--testsuite=unit"
"--testsuite=integration"
"-v"
"--verbose"
"--verbose"
]
Noogle detected
Implementation
The following is the current implementation of this function.
toCommandLineGNU =
{
isLong ? optionName: builtins.stringLength optionName > 1,
explicitBool ? false,
formatArg ? lib.generators.mkValueStringDefault { },
}:
let
optionFormat = optionName: {
option = if isLong optionName then "--${optionName}" else "-${optionName}";
sep = if isLong optionName then "=" else "";
inherit explicitBool formatArg;
};
in
lib.cli.toCommandLine optionFormat;