diff options
author | Profpatsch <mail@profpatsch.de> | 2020-01-22 23:37:10 +0100 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2020-01-23 14:47:38 +0100 |
commit | b2654c226a83aa4cf5948f04ea6370796a2c7055 (patch) | |
tree | d4b6a29b2b78c624f9caf91fa37be5be6b318674 | |
parent | 6841f408cc7f42e3eaa59b06351008da2b1aa270 (diff) |
lib/cli,lib/tests/misc: somewhat more standard formatting
-rw-r--r-- | lib/cli.nix | 78 | ||||
-rw-r--r-- | lib/tests/misc.nix | 61 |
2 files changed, 62 insertions, 77 deletions
diff --git a/lib/cli.nix b/lib/cli.nix index 32d24a00ceb0..a0e85c396057 100644 --- a/lib/cli.nix +++ b/lib/cli.nix @@ -10,49 +10,44 @@ rec { `toGNUCommandLineShell` returns an escaped shell string. Example: - 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; - }; - => [ "-X" "PUT" "--data" "{\"id\":0}" "--retry" "3" "--url" "https://example.com/foo" "--url" "https://example.com/bar" "--verbose" ] - - toGNUCommandLineShell - { } - { 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'" - + 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; + } + => [ + "-X" "PUT" + "--data" "{\"id\":0}" + "--retry" "3" + "--url" "https://example.com/foo" + "--url" "https://example.com/bar" + "--verbose" + ] + + cli.toGNUCommandLineShell {} { + 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'"; */ toGNUCommandLineShell = options: attrs: lib.escapeShellArgs (toGNUCommandLine options attrs); toGNUCommandLine = { renderKey ? - key: if builtins.stringLength key == 1 then "-${key}" else "--${key}" + key: + if builtins.stringLength key == 1 + then "-${key}" + else "--${key}" , renderOption ? key: value: @@ -66,11 +61,10 @@ rec { }: options: let - render = key: value: - if builtins.isBool value - then renderBool key value - else if builtins.isList value - then renderList key value + render = + key: value: + if builtins.isBool value then renderBool key value + else if builtins.isList value then renderList key value else renderOption key value; in diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index b320839b2ac7..59ed1e507e24 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -445,45 +445,36 @@ runTests { # 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; - }; + 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" ]; + 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; }; - - X = "PUT"; - - retry = 3; - - retry-delay = null; - - url = [ "https://example.com/foo" "https://example.com/bar" ]; - - silent = false; - - verbose = true; - }; + expr = cli.toGNUCommandLineShell {} { + 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'"; }; |