diff options
author | Alyssa Ross <hi@alyssa.is> | 2024-04-10 20:43:08 +0200 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2024-04-10 20:43:08 +0200 |
commit | 69bfdf2484041b9d242840c4e5017b4703383bb0 (patch) | |
tree | d8bdaa69e7990d7d6f09b594b3c425f742acd2d0 /nixpkgs/lib/cli.nix | |
parent | c8aee4b4363b6bf905a521b05b7476960e8286c8 (diff) | |
parent | d8fe5e6c92d0d190646fb9f1056741a229980089 (diff) | |
download | nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar.gz nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar.bz2 nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar.lz nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar.xz nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar.zst nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.zip |
Merge commit 'd8fe5e6c'
Conflicts: nixpkgs/pkgs/build-support/go/module.nix
Diffstat (limited to 'nixpkgs/lib/cli.nix')
-rw-r--r-- | nixpkgs/lib/cli.nix | 95 |
1 files changed, 58 insertions, 37 deletions
diff --git a/nixpkgs/lib/cli.nix b/nixpkgs/lib/cli.nix index c96d4dbb0432..fcffacb5ea99 100644 --- a/nixpkgs/lib/cli.nix +++ b/nixpkgs/lib/cli.nix @@ -1,43 +1,64 @@ { lib }: rec { - /* Automatically convert an attribute set to command-line options. - - This helps protect against malformed command lines and also to reduce - boilerplate related to command-line construction for simple use cases. - - `toGNUCommandLine` returns a list of nix strings. - `toGNUCommandLineShell` returns an escaped shell string. - - Example: - 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'"; + /** + Automatically convert an attribute set to command-line options. + + This helps protect against malformed command lines and also to reduce + boilerplate related to command-line construction for simple use cases. + + `toGNUCommandLine` returns a list of nix strings. + + `toGNUCommandLineShell` returns an escaped shell string. + + + # Inputs + + `options` + + : 1\. Function argument + + `attrs` + + : 2\. Function argument + + + # Examples + :::{.example} + ## `lib.cli.toGNUCommandLineShell` usage example + + ```nix + 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); |