lib/cli: encodeGNUCommandLine -> toGNUCommandLineShell

The semantic difference between `encode` and `to` is not apparent.
Users are likely to confuse both functions (which leads to unexpected
error messages about the wrong types). Like in `generators.nix`, all
functions should be prefixed by `to`.

Furthermore, converting to a string depends on the target context. In
this case, it’s a POSIX shell, so we should name it that (compare
`escapeShellArg` in `strings.nix`).

We can later add versions that escape for embedding in e.g. python
scripts or similar.
This commit is contained in:
Profpatsch
2020-01-23 14:47:38 +01:00
parent 88a7f65c83
commit 582354d3b6
2 changed files with 51 additions and 4 deletions
+27 -2
View File
@@ -441,9 +441,34 @@ runTests {
expected = "«foo»";
};
testRenderOptions = {
# CLI
testToGNUCommandLine = {
expr =
encodeGNUCommandLine
cli.toGNUCommandLine
{ }
{ 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; };