aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGabriel Gonzalez <Gabriel439@gmail.com>2019-12-15 08:21:41 -0800
committerGabriel Gonzalez <Gabriel439@gmail.com>2019-12-15 08:21:41 -0800
commit5edd4dd44c5f3de1886744aeac49bd396c24f966 (patch)
tree5811d2f007c2505ba34f4bbca81ca941183195dc /lib
parent693096d283763ce71fcd2002d965c07546aaafda (diff)
Use a more realistic example that exercises all encodings
... as suggested by @roberth This also caught a bug in rendering lists, which this change also fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/cli.nix21
-rw-r--r--lib/tests/misc.nix16
2 files changed, 28 insertions, 9 deletions
diff --git a/lib/cli.nix b/lib/cli.nix
index f3a81cb9e9c4..b6703b2ca825 100644
--- a/lib/cli.nix
+++ b/lib/cli.nix
@@ -6,8 +6,23 @@
boilerplate related to command-line construction for simple use cases.
Example:
- encodeGNUCommandLine { } { foo = "A"; bar = 1; baz = null; qux = true; v = true; }
- => " --bar '1' --foo 'A' --qux -v"
+ encodeGNUCommandLine
+ { }
+ { 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;
+ };
+ => " -X 'PUT' --data '{\"id\":0}' --retry '3' --url 'https://example.com/foo' --url 'https://example.com/bar' --verbose"
*/
encodeGNUCommandLine =
{ renderKey ?
@@ -21,7 +36,7 @@
, renderBool ? key: value: if value then " ${renderKey key}" else ""
- , renderList ? key: value: lib.concatMapStrings renderOption value
+ , renderList ? key: value: lib.concatMapStrings (renderOption key) value
}:
options:
let
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index 021d0e88c919..29c5fad91f92 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -445,17 +445,21 @@ runTests {
expr =
encodeGNUCommandLine
{ }
- { foo = "A";
+ { data = builtins.toJSON { id = 0; };
- bar = 1;
+ X = "PUT";
- baz = null;
+ retry = 3;
- qux = true;
+ retry-delay = null;
- v = true;
+ url = [ "https://example.com/foo" "https://example.com/bar" ];
+
+ silent = false;
+
+ verbose = true;
};
- expected = " --bar '1' --foo 'A' --qux -v";
+ expected = " -X 'PUT' --data '{\"id\":0}' --retry '3' --url 'https://example.com/foo' --url 'https://example.com/bar' --verbose";
};
}