mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
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:
parent
693096d283
commit
5edd4dd44c
21
lib/cli.nix
21
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
|
||||
|
@ -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";
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user