From 5edd4dd44c5f3de1886744aeac49bd396c24f966 Mon Sep 17 00:00:00 2001 From: Gabriel Gonzalez Date: Sun, 15 Dec 2019 08:21:41 -0800 Subject: 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 --- lib/cli.nix | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'lib/cli.nix') diff --git a/lib/cli.nix b/lib/cli.nix index f3a81cb9e9c47..b6703b2ca8258 100644 --- a/lib/cli.nix +++ b/lib/cli.nix @@ -6,8 +6,23 @@ boilerplate related to command-line construction for simple use cases. Example: - encodeGNUCommandLine { } { foo = "A"; bar = 1; baz = null; qux = true; v = true; } - => " --bar '1' --foo 'A' --qux -v" + encodeGNUCommandLine + { } + { 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 = { renderKey ? @@ -21,7 +36,7 @@ , 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: let -- cgit 1.4.1