diff options
author | Profpatsch <mail@profpatsch.de> | 2020-01-22 23:24:06 +0100 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2020-01-23 14:47:38 +0100 |
commit | 582354d3b6161384cf69a90f6c00d7e29382950a (patch) | |
tree | e38cd6623da82c4154a3aae433e2db7fba7e4d9a /lib/tests | |
parent | 88a7f65c834ec09ce9df0c23c9935630e17a0c4a (diff) | |
download | nixlib-582354d3b6161384cf69a90f6c00d7e29382950a.tar nixlib-582354d3b6161384cf69a90f6c00d7e29382950a.tar.gz nixlib-582354d3b6161384cf69a90f6c00d7e29382950a.tar.bz2 nixlib-582354d3b6161384cf69a90f6c00d7e29382950a.tar.lz nixlib-582354d3b6161384cf69a90f6c00d7e29382950a.tar.xz nixlib-582354d3b6161384cf69a90f6c00d7e29382950a.tar.zst nixlib-582354d3b6161384cf69a90f6c00d7e29382950a.zip |
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.
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/misc.nix | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index e47b48b5017d..b320839b2ac7 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; }; |