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
This commit is contained in:
Gabriel Gonzalez 2019-12-15 08:21:41 -08:00
parent 693096d283
commit 5edd4dd44c
2 changed files with 28 additions and 9 deletions

View File

@ -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

View File

@ -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";
};
}