From 8815b565cb765aa8315d13feee376470dc8f139c Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Sun, 12 Jan 2025 19:59:14 -0500 Subject: [PATCH] lib/cli: add `wrappingValueString` option The function currently doesn't provide a way to create a result like `--foo "bar"` or `--foo="bar"`, where the argument is quoted. This option resolves that. We set it to an empty string by default, so we can always interpolate it into the string, even if the user didn't set it. --- lib/cli.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/cli.nix b/lib/cli.nix index 38bba26771037b..a62abce6c9f324 100644 --- a/lib/cli.nix +++ b/lib/cli.nix @@ -84,6 +84,13 @@ rec { By default, the separator is set to a space, so option `-c` and value `5` would become ["-c 5"]. This is useful if the command requires equals, for example, `-c=5`. + `wrappingValueString` + + : The string to surround an option's value with. + Values aren't quoted by default, so option `foo` and value `bar` would become ["--foo bar"] + This is useful if your value could be misinterpreted by your shell without quoting. + For example, if you wanted a result of `["--foo \"bar\" "]`, you could set `wrappingValueString` to a literal quote. + # Examples :::{.example} ## `lib.cli.toGNUCommandLine` usage example @@ -120,6 +127,8 @@ rec { optionValueSeparator ? " ", # Space by default, reflecting `--foo bar` + wrappingValueString ? "", + mkOption ? k: v: if v == null then @@ -129,7 +138,9 @@ rec { (lib.concatStrings [ (mkOptionName k) optionValueSeparator + wrappingValueString (lib.generators.mkValueStringDefault { } v) + wrappingValueString ]) ], }: