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.
|
boilerplate related to command-line construction for simple use cases.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
encodeGNUCommandLine { } { foo = "A"; bar = 1; baz = null; qux = true; v = true; }
|
encodeGNUCommandLine
|
||||||
=> " --bar '1' --foo 'A' --qux -v"
|
{ }
|
||||||
|
{ 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 =
|
encodeGNUCommandLine =
|
||||||
{ renderKey ?
|
{ renderKey ?
|
||||||
|
@ -21,7 +36,7 @@
|
||||||
|
|
||||||
, renderBool ? key: value: if value then " ${renderKey key}" else ""
|
, 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:
|
options:
|
||||||
let
|
let
|
||||||
|
|
|
@ -445,17 +445,21 @@ runTests {
|
||||||
expr =
|
expr =
|
||||||
encodeGNUCommandLine
|
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 a new issue