From 582354d3b6161384cf69a90f6c00d7e29382950a Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Wed, 22 Jan 2020 23:24:06 +0100 Subject: lib/cli: encodeGNUCommandLine -> toGNUCommandLineShell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/tests/misc.nix | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'lib/tests') diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index e47b48b5017d1..b320839b2ac7b 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -441,9 +441,34 @@ runTests { expected = "«foo»"; }; - testRenderOptions = { + +# CLI + + testToGNUCommandLine = { + expr = + 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 = - encodeGNUCommandLine + cli.toGNUCommandLineShell { } { data = builtins.toJSON { id = 0; }; -- cgit 1.4.1