diff options
author | Silvan Mosberger <contact@infinisil.com> | 2024-05-24 23:25:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-24 23:25:28 +0200 |
commit | 6c42e8745a8e636ccd0b16132c27cd2484b8520f (patch) | |
tree | 816e7a6da0a07043099d500d79706f0901e487f8 /lib | |
parent | b64987ff75142db5e924ebb3749e4c521d566405 (diff) | |
parent | 5458b62cf785f02ef25f5312da8f2ce172bafcf3 (diff) | |
download | nixlib-6c42e8745a8e636ccd0b16132c27cd2484b8520f.tar nixlib-6c42e8745a8e636ccd0b16132c27cd2484b8520f.tar.gz nixlib-6c42e8745a8e636ccd0b16132c27cd2484b8520f.tar.bz2 nixlib-6c42e8745a8e636ccd0b16132c27cd2484b8520f.tar.lz nixlib-6c42e8745a8e636ccd0b16132c27cd2484b8520f.tar.xz nixlib-6c42e8745a8e636ccd0b16132c27cd2484b8520f.tar.zst nixlib-6c42e8745a8e636ccd0b16132c27cd2484b8520f.zip |
Merge pull request #309517 from bobrippling/fix/ebusd-args
Fix ebusd service argument passing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cli.nix | 11 | ||||
-rw-r--r-- | lib/tests/misc.nix | 21 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/cli.nix b/lib/cli.nix index fcffacb5ea99..311037c519a6 100644 --- a/lib/cli.nix +++ b/lib/cli.nix @@ -90,7 +90,16 @@ rec { mkOption ? k: v: if v == null then [] - else [ (mkOptionName k) (lib.generators.mkValueStringDefault {} v) ] + else if optionValueSeparator == null then + [ (mkOptionName k) (lib.generators.mkValueStringDefault {} v) ] + else + [ "${mkOptionName k}${optionValueSeparator}${lib.generators.mkValueStringDefault {} v}" ], + + # how to separate an option from its flag; + # by default, there is no separator, so option `-c` and value `5` + # would become ["-c" "5"]. + # This is useful if the command requires equals, for example, `-c=5`. + optionValueSeparator ? null }: options: let diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 6774939023d2..408ea5416293 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -1639,6 +1639,27 @@ runTests { ]; }; + testToGNUCommandLineSeparator = { + expr = cli.toGNUCommandLine { optionValueSeparator = "="; } { + data = builtins.toJSON { id = 0; }; + X = "PUT"; + retry = 3; + retry-delay = null; + url = [ "https://example.com/foo" "https://example.com/bar" ]; + silent = false; + verbose = true; + }; + + expected = [ + "-X=PUT" + "--data={\"id\":0}" + "--retry=3" + "--url=https://example.com/foo" + "--url=https://example.com/bar" + "--verbose" + ]; + }; + testToGNUCommandLineShell = { expr = cli.toGNUCommandLineShell {} { data = builtins.toJSON { id = 0; }; |