Skip to content

Commit

Permalink
lib/cli: add wrappingValueString option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
llakala committed Jan 13, 2025
1 parent 4697054 commit 8815b56
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/cli.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,6 +127,8 @@ rec {

optionValueSeparator ? " ", # Space by default, reflecting `--foo bar`

wrappingValueString ? "",

mkOption ?
k: v:
if v == null then
Expand All @@ -129,7 +138,9 @@ rec {
(lib.concatStrings [
(mkOptionName k)
optionValueSeparator
wrappingValueString
(lib.generators.mkValueStringDefault { } v)
wrappingValueString
])
],
}:
Expand Down

0 comments on commit 8815b56

Please sign in to comment.