Skip to content

Commit fcc8f21

Browse files
committed
[GenerateDocCReference] Improve filtering and categorization of arguments in documentation with sectionTitle
1 parent d67151b commit fcc8f21

File tree

14 files changed

+298
-127
lines changed

14 files changed

+298
-127
lines changed

Sources/ArgumentParserToolInfo/ToolInfo.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,23 @@ public struct ArgumentInfoV0: Codable, Hashable {
218218
self.kind = kind
219219

220220
self.shouldDisplay = shouldDisplay
221-
self.sectionTitle = sectionTitle
221+
222+
// The section title helps categorize arguments
223+
// for better organization in documentation.
224+
225+
// The switch statement checks the kind of argument
226+
// and assigns a default section title related to the argument type
227+
// if the provided one is nil.
228+
switch kind {
229+
case .positional:
230+
self.sectionTitle = sectionTitle ?? "Arguments"
231+
232+
case .option:
233+
self.sectionTitle = sectionTitle ?? "Optionals"
234+
235+
case .flag:
236+
self.sectionTitle = sectionTitle ?? "Flags"
237+
}
222238

223239
self.isOptional = isOptional
224240
self.isRepeating = isRepeating

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testColorDoccReference().md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,28 @@
66
color --fav=<fav> [--second=<second>] [--help]
77
```
88

9-
**--fav=\<fav\>:**
9+
## Flags
10+
11+
**`--help`**
12+
13+
*Show help information.*
14+
15+
16+
## Optionals
17+
18+
**`--fav=\<fav\>`**
1019

1120
*Your favorite color.*
1221

1322

14-
**--second=\<second\>:**
23+
**`--second=\<second\>`**
1524

1625
*Your second favorite color.*
1726

1827
This is optional.
1928

2029

21-
**--help:**
22-
23-
*Show help information.*
24-
30+
## Subcommands
2531

2632
## color.help
2733

@@ -31,9 +37,6 @@ Show subcommand help information.
3137
color help [<subcommands>...]
3238
```
3339

34-
**subcommands:**
35-
36-
37-
38-
40+
## Arguments
3941

42+
**`subcommands`**

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testCountLinesDoccReference().md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,34 @@
66
count-lines [<input-file>] [--prefix=<prefix>] [--verbose] [--help]
77
```
88

9-
**input-file:**
10-
11-
*A file to count lines in. If omitted, counts the lines of stdin.*
9+
## Arguments
1210

11+
**`input-file`**
1312

14-
**--prefix=\<prefix\>:**
13+
*A file to count lines in. If omitted, counts the lines of stdin.*
1514

16-
*Only count lines with this prefix.*
1715

16+
## Flags
1817

19-
**--verbose:**
18+
**`--verbose`**
2019

2120
*Include extra information in the output.*
2221

2322

24-
**--help:**
23+
**`--help`**
2524

2625
*Show help information.*
2726

2827

28+
## Optionals
29+
30+
**`--prefix=\<prefix\>`**
31+
32+
*Only count lines with this prefix.*
33+
34+
35+
## Subcommands
36+
2937
## count-lines.help
3038

3139
Show subcommand help information.
@@ -34,9 +42,6 @@ Show subcommand help information.
3442
count-lines help [<subcommands>...]
3543
```
3644

37-
**subcommands:**
38-
39-
40-
41-
45+
## Arguments
4246

47+
**`subcommands`**

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testMathDoccReference().md

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ A utility for performing maths.
88
math [--version] [--help]
99
```
1010

11-
**--version:**
11+
## Flags
12+
13+
**`--version`**
1214

1315
*Show the version.*
1416

1517

16-
**--help:**
18+
**`--help`**
1719

1820
*Show help information.*
1921

2022

23+
## Subcommands
24+
2125
## math.add
2226

2327
Print the sum of the values.
@@ -26,76 +30,78 @@ Print the sum of the values.
2630
math add [--hex-output] [<values>...] [--version] [--help]
2731
```
2832

29-
**--hex-output:**
30-
31-
*Use hexadecimal notation for the result.*
32-
33+
## Arguments
3334

34-
**values:**
35+
**`values`**
3536

3637
*A group of integers to operate on.*
3738

3839

39-
**--version:**
40+
## Flags
4041

41-
*Show the version.*
42+
**`--hex-output`**
4243

44+
*Use hexadecimal notation for the result.*
4345

44-
**--help:**
4546

46-
*Show help information.*
47+
**`--version`**
4748

49+
*Show the version.*
4850

4951

52+
**`--help`**
5053

51-
## math.multiply
54+
*Show help information.*## math.multiply
5255

5356
Print the product of the values.
5457

5558
```
5659
math multiply [--hex-output] [<values>...] [--version] [--help]
5760
```
5861

59-
**--hex-output:**
60-
61-
*Use hexadecimal notation for the result.*
62+
## Arguments
6263

63-
64-
**values:**
64+
**`values`**
6565

6666
*A group of integers to operate on.*
6767

6868

69-
**--version:**
69+
## Flags
7070

71-
*Show the version.*
71+
**`--hex-output`**
7272

73+
*Use hexadecimal notation for the result.*
7374

74-
**--help:**
7575

76-
*Show help information.*
76+
**`--version`**
7777

78+
*Show the version.*
7879

7980

81+
**`--help`**
8082

81-
## math.stats
83+
*Show help information.*## math.stats
8284

8385
Calculate descriptive statistics.
8486

8587
```
8688
math stats [--version] [--help]
8789
```
8890

89-
**--version:**
91+
## Flags
92+
93+
**`--version`**
9094

9195
*Show the version.*
9296

9397

94-
**--help:**
98+
**`--help`**
9599

96100
*Show help information.*
97101

98102

103+
## Subcommands
104+
99105
### math.stats.average
100106

101107
Print the average of the values.
@@ -104,109 +110,105 @@ Print the average of the values.
104110
math stats average [--kind=<kind>] [<values>...] [--version] [--help]
105111
```
106112

107-
**--kind=\<kind\>:**
108-
109-
*The kind of average to provide.*
113+
## Arguments
110114

111-
112-
**values:**
115+
**`values`**
113116

114117
*A group of floating-point values to operate on.*
115118

116119

117-
**--version:**
120+
## Flags
121+
122+
**`--version`**
118123

119124
*Show the version.*
120125

121126

122-
**--help:**
127+
**`--help`**
123128

124129
*Show help information.*
125130

126131

132+
## Optionals
127133

134+
**`--kind=\<kind\>`**
128135

129-
### math.stats.stdev
136+
*The kind of average to provide.*### math.stats.stdev
130137

131138
Print the standard deviation of the values.
132139

133140
```
134141
math stats stdev [<values>...] [--version] [--help]
135142
```
136143

137-
**values:**
144+
## Arguments
138145

139-
*A group of floating-point values to operate on.*
140-
141-
142-
**--version:**
146+
**`values`**
143147

144-
*Show the version.*
148+
*A group of floating-point values to operate on.*
145149

146150

147-
**--help:**
151+
## Flags
148152

149-
*Show help information.*
153+
**`--version`**
150154

155+
*Show the version.*
151156

152157

158+
**`--help`**
153159

154-
### math.stats.quantiles
160+
*Show help information.*### math.stats.quantiles
155161

156162
Print the quantiles of the values (TBD).
157163

158164
```
159165
math stats quantiles [<one-of-four>] [<custom-arg>] [<values>...] [--file=<file>] [--directory=<directory>] [--shell=<shell>] [--custom=<custom>] [--version] [--help]
160166
```
161167

162-
**one-of-four:**
163-
164-
165-
**custom-arg:**
166-
168+
## Arguments
167169

168-
**values:**
170+
**`one-of-four`**
169171

170-
*A group of floating-point values to operate on.*
171172

173+
**`custom-arg`**
172174

173-
**--file=\<file\>:**
174175

176+
**`values`**
175177

176-
**--directory=\<directory\>:**
178+
*A group of floating-point values to operate on.*
177179

178180

179-
**--shell=\<shell\>:**
181+
## Flags
180182

183+
**`--version`**
181184

182-
**--custom=\<custom\>:**
185+
*Show the version.*
183186

184187

185-
**--version:**
188+
**`--help`**
186189

187-
*Show the version.*
190+
*Show help information.*
188191

189192

190-
**--help:**
193+
## Optionals
191194

192-
*Show help information.*
195+
**`--file=\<file\>`**
193196

194197

198+
**`--directory=\<directory\>`**
195199

196200

201+
**`--shell=\<shell\>`**
197202

198203

199-
## math.help
204+
**`--custom=\<custom\>`**## math.help
200205

201206
Show subcommand help information.
202207

203208
```
204209
math help [<subcommands>...]
205210
```
206211

207-
**subcommands:**
208-
209-
210-
211-
212+
## Arguments
212213

214+
**`subcommands`**

0 commit comments

Comments
 (0)