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:
+27
-2
@@ -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; };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user