|
6 | 6 | (let required (= kind "value"))
|
7 | 7 | (let value default)
|
8 | 8 |
|
9 |
| - (fun ( |
10 |
| - &kind |
| 9 | + (fun (&kind |
11 | 10 | &name
|
12 | 11 | &desc
|
13 | 12 | &default
|
|
17 | 16 | (let _group (fun (children all_of) {
|
18 | 17 | (let kind "group")
|
19 | 18 |
|
20 |
| - (fun ( |
21 |
| - &kind |
| 19 | + (fun (&kind |
22 | 20 | &children
|
23 | 21 | &all_of) ()) }))
|
24 | 22 |
|
25 | 23 | # @brief Defines a command line flag
|
26 | 24 | # @details All flags are optional and turned off
|
27 | 25 | # @param name how the flag is named, eg "--debug"
|
28 | 26 | # @param desc what the flag achieves
|
29 |
| -(let flag (fun (name desc) |
30 |
| - (_param name desc false "flag"))) |
| 27 | +(let flag (fun (name desc) (_param name desc false "flag"))) |
31 | 28 |
|
32 | 29 | # @brief Defines a command line value
|
33 | 30 | # @details All values are required and equal to their default value
|
34 | 31 | # @param name how the value is named, eg "filename"
|
35 | 32 | # @param desc what the value is for
|
36 | 33 | # @param default default value for the value
|
37 |
| -(let value (fun (name desc default) |
38 |
| - (_param name desc default "value"))) |
| 34 | +(let value (fun (name desc default) (_param name desc default "value"))) |
39 | 35 |
|
40 | 36 | # @brief Creates a group of flags/values/groups where only one of the subgroup has to match
|
41 | 37 | # @param params list of flags/values/groups
|
42 |
| -(let oneOf (fun (params) |
43 |
| - (_group params false))) |
| 38 | +(let oneOf (fun (params) (_group params false))) |
44 | 39 |
|
45 | 40 | # @brief Creates a group of flags/values/groups where all of the subgroups have to match
|
46 | 41 | # @param params list of flags/values/groups
|
47 |
| -(let group (fun (params) |
48 |
| - (_group params true))) |
| 42 | +(let group (fun (params) (_group params true))) |
49 | 43 |
|
50 | 44 | (let _synopsis_group (fun (cli)
|
51 | 45 | (if cli.all_of
|
52 | 46 | {
|
53 |
| - (let partially_fmt (map |
54 |
| - cli.children |
55 |
| - (fun (param) (_format_param param)))) |
| 47 | + (let partially_fmt (map cli.children (fun (param) (_format_param param)))) |
56 | 48 |
|
57 | 49 | (mut options [""])
|
58 | 50 | (mut i 0)
|
|
61 | 53 | (let e (@ partially_fmt i))
|
62 | 54 | (if (= (type e) "String")
|
63 | 55 | (set options (map
|
64 |
| - options |
65 |
| - (fun (alt) |
66 |
| - (if (empty? alt) |
67 |
| - e |
68 |
| - (format "{} {}" alt e))))) |
| 56 | + options |
| 57 | + (fun (alt) |
| 58 | + (if (empty? alt) |
| 59 | + e |
| 60 | + (format "{} {}" alt e))))) |
69 | 61 | # if we have a list, add (@ options 0) to each element of the list, then added to options
|
70 | 62 | (concat! options (map e (fun (alt) (format "{} {}" (@ options 0) alt)))))
|
71 | 63 | (set i (+ 1 i)) })
|
72 | 64 |
|
73 |
| - options |
74 |
| - } |
| 65 | + options } |
75 | 66 | # any_of, return a list of each formatted param
|
76 |
| - (flatMap |
77 |
| - cli.children |
78 |
| - (fun (param) (_format_param param)))))) |
| 67 | + (flatMap cli.children (fun (param) (_format_param param)))))) |
79 | 68 |
|
80 | 69 | (let _synopsis_flag (fun (param)
|
81 | 70 | (if param.required
|
82 | 71 | (format "{}" cli.name)
|
83 | 72 | (format "[{}]" cli.name))))
|
84 | 73 |
|
85 |
| -(let _synopsis_value (fun (param) |
86 |
| - (format "<{}>" cli.name))) |
| 74 | +(let _synopsis_value (fun (param) (format "<{}>" cli.name))) |
87 | 75 |
|
88 | 76 | (let _format_param (fun (cli)
|
89 | 77 | (if (= cli.kind "group")
|
|
95 | 83 |
|
96 | 84 | (let _get_options (fun (d param)
|
97 | 85 | (if (= param.kind "group")
|
98 |
| - (forEach |
99 |
| - param.children |
100 |
| - (fun (p) (_get_options d p))) |
| 86 | + (forEach param.children (fun (p) (_get_options d p))) |
101 | 87 | (dict:add d param.name param))))
|
102 | 88 |
|
103 | 89 | (let help (fun (program desc cli) {
|
|
109 | 95 | (let params (dict))
|
110 | 96 | (_get_options params cli)
|
111 | 97 | (let options (join
|
112 |
| - (map (dict:keys params) (fun (name) { |
113 |
| - (let param (dict:get params name)) |
114 |
| - (let fmt_name (if (= param.kind "value") (format "<{}>" name) name)) |
115 |
| - (format "\t{:<28} {}" fmt_name param.desc) })) |
116 |
| - "\n")) |
| 98 | + (map |
| 99 | + (dict:keys params) |
| 100 | + (fun (name) { |
| 101 | + (let param (dict:get params name)) |
| 102 | + (let fmt_name |
| 103 | + (if (= param.kind "value") |
| 104 | + (format "<{}>" name) |
| 105 | + name)) |
| 106 | + (format "\t{:<28} {}" fmt_name param.desc) })) |
| 107 | + "\n")) |
117 | 108 |
|
118 | 109 | (+ headers synopsis "\n\nOPTIONS\n" options) }))
|
119 | 110 |
|
|
198 | 189 | (if (= cli.kind "flag")
|
199 | 190 | {
|
200 | 191 | (let maybe_flag (find args cli.name))
|
201 |
| - (if (!= maybe_flag -1) |
202 |
| - (dict:add parsed cli.name true)) } |
| 192 | + (if (!= maybe_flag -1) (dict:add parsed cli.name true)) } |
203 | 193 | (if (= cli.kind "value")
|
204 | 194 | (dict:add parsed cli.name (head args))
|
205 | 195 | # group
|
206 |
| - (if cli.all_of (_match_group parsed args cli) (_match_one_of parsed args cli)))) |
| 196 | + (if cli.all_of |
| 197 | + (_match_group parsed args cli) |
| 198 | + (_match_one_of parsed args cli)))) |
207 | 199 |
|
208 | 200 | parsed }))
|
209 |
| - |
0 commit comments