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