lol

doc: migrate lib.cli to use doc-comments

+54 -33
+54 -33
lib/cli.nix
··· 1 1 { lib }: 2 2 3 3 rec { 4 - /* Automatically convert an attribute set to command-line options. 4 + /** 5 + Automatically convert an attribute set to command-line options. 6 + 7 + This helps protect against malformed command lines and also to reduce 8 + boilerplate related to command-line construction for simple use cases. 9 + 10 + `toGNUCommandLine` returns a list of nix strings. 5 11 6 - This helps protect against malformed command lines and also to reduce 7 - boilerplate related to command-line construction for simple use cases. 12 + `toGNUCommandLineShell` returns an escaped shell string. 13 + 14 + 15 + # Inputs 16 + 17 + `options` 18 + 19 + : 1\. Function argument 20 + 21 + `attrs` 22 + 23 + : 2\. Function argument 8 24 9 - `toGNUCommandLine` returns a list of nix strings. 10 - `toGNUCommandLineShell` returns an escaped shell string. 25 + 26 + # Examples 27 + :::{.example} 28 + ## `lib.cli.toGNUCommandLineShell` usage example 29 + 30 + ```nix 31 + cli.toGNUCommandLine {} { 32 + data = builtins.toJSON { id = 0; }; 33 + X = "PUT"; 34 + retry = 3; 35 + retry-delay = null; 36 + url = [ "https://example.com/foo" "https://example.com/bar" ]; 37 + silent = false; 38 + verbose = true; 39 + } 40 + => [ 41 + "-X" "PUT" 42 + "--data" "{\"id\":0}" 43 + "--retry" "3" 44 + "--url" "https://example.com/foo" 45 + "--url" "https://example.com/bar" 46 + "--verbose" 47 + ] 11 48 12 - Example: 13 - cli.toGNUCommandLine {} { 14 - data = builtins.toJSON { id = 0; }; 15 - X = "PUT"; 16 - retry = 3; 17 - retry-delay = null; 18 - url = [ "https://example.com/foo" "https://example.com/bar" ]; 19 - silent = false; 20 - verbose = true; 21 - } 22 - => [ 23 - "-X" "PUT" 24 - "--data" "{\"id\":0}" 25 - "--retry" "3" 26 - "--url" "https://example.com/foo" 27 - "--url" "https://example.com/bar" 28 - "--verbose" 29 - ] 49 + cli.toGNUCommandLineShell {} { 50 + data = builtins.toJSON { id = 0; }; 51 + X = "PUT"; 52 + retry = 3; 53 + retry-delay = null; 54 + url = [ "https://example.com/foo" "https://example.com/bar" ]; 55 + silent = false; 56 + verbose = true; 57 + } 58 + => "'-X' 'PUT' '--data' '{\"id\":0}' '--retry' '3' '--url' 'https://example.com/foo' '--url' 'https://example.com/bar' '--verbose'"; 59 + ``` 30 60 31 - cli.toGNUCommandLineShell {} { 32 - data = builtins.toJSON { id = 0; }; 33 - X = "PUT"; 34 - retry = 3; 35 - retry-delay = null; 36 - url = [ "https://example.com/foo" "https://example.com/bar" ]; 37 - silent = false; 38 - verbose = true; 39 - } 40 - => "'-X' 'PUT' '--data' '{\"id\":0}' '--retry' '3' '--url' 'https://example.com/foo' '--url' 'https://example.com/bar' '--verbose'"; 61 + ::: 41 62 */ 42 63 toGNUCommandLineShell = 43 64 options: attrs: lib.escapeShellArgs (toGNUCommandLine options attrs);