Skip to content

Commit 806544c

Browse files
committed
fix: handle the assignment of the default sectionTitle value in the generate-docc command instead of in toolinfo
1 parent fcc8f21 commit 806544c

14 files changed

+81
-161
lines changed

Sources/ArgumentParserToolInfo/ToolInfo.swift

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

220220
self.shouldDisplay = shouldDisplay
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-
}
221+
self.sectionTitle = sectionTitle
238222

239223
self.isOptional = isOptional
240224
self.isRepeating = isRepeating

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testColorDoccReference().md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ color --fav=<fav> [--second=<second>] [--help]
1313
*Show help information.*
1414

1515

16-
## Optionals
16+
## Options
1717

1818
**`--fav=\<fav\>`**
1919

@@ -37,6 +37,6 @@ Show subcommand help information.
3737
color help [<subcommands>...]
3838
```
3939

40-
## Arguments
40+
## General
4141

4242
**`subcommands`**

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testCountLinesDoccReference().md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ count-lines [<input-file>] [--prefix=<prefix>] [--verbose] [--help]
2525
*Show help information.*
2626

2727

28-
## Optionals
28+
## Options
2929

3030
**`--prefix=\<prefix\>`**
3131

@@ -42,6 +42,6 @@ Show subcommand help information.
4242
count-lines help [<subcommands>...]
4343
```
4444

45-
## Arguments
45+
## General
4646

4747
**`subcommands`**

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testMathDoccReference().md

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,16 @@ Print the sum of the values.
3030
math add [--hex-output] [<values>...] [--version] [--help]
3131
```
3232

33-
## Arguments
33+
## General
3434

35-
**`values`**
36-
37-
*A group of integers to operate on.*
35+
**`--hex-output`**
3836

37+
*Use hexadecimal notation for the result.*
3938

40-
## Flags
4139

42-
**`--hex-output`**
40+
**`values`**
4341

44-
*Use hexadecimal notation for the result.*
42+
*A group of integers to operate on.*
4543

4644

4745
**`--version`**
@@ -59,18 +57,16 @@ Print the product of the values.
5957
math multiply [--hex-output] [<values>...] [--version] [--help]
6058
```
6159

62-
## Arguments
60+
## General
6361

64-
**`values`**
65-
66-
*A group of integers to operate on.*
62+
**`--hex-output`**
6763

64+
*Use hexadecimal notation for the result.*
6865

69-
## Flags
7066

71-
**`--hex-output`**
67+
**`values`**
7268

73-
*Use hexadecimal notation for the result.*
69+
*A group of integers to operate on.*
7470

7571

7672
**`--version`**
@@ -88,7 +84,7 @@ Calculate descriptive statistics.
8884
math stats [--version] [--help]
8985
```
9086

91-
## Flags
87+
## General
9288

9389
**`--version`**
9490

@@ -110,46 +106,40 @@ Print the average of the values.
110106
math stats average [--kind=<kind>] [<values>...] [--version] [--help]
111107
```
112108

113-
## Arguments
109+
## General
110+
111+
**`--kind=\<kind\>`**
112+
113+
*The kind of average to provide.*
114+
114115

115116
**`values`**
116117

117118
*A group of floating-point values to operate on.*
118119

119120

120-
## Flags
121-
122121
**`--version`**
123122

124123
*Show the version.*
125124

126125

127126
**`--help`**
128127

129-
*Show help information.*
130-
131-
132-
## Optionals
133-
134-
**`--kind=\<kind\>`**
135-
136-
*The kind of average to provide.*### math.stats.stdev
128+
*Show help information.*### math.stats.stdev
137129

138130
Print the standard deviation of the values.
139131

140132
```
141133
math stats stdev [<values>...] [--version] [--help]
142134
```
143135

144-
## Arguments
136+
## General
145137

146138
**`values`**
147139

148140
*A group of floating-point values to operate on.*
149141

150142

151-
## Flags
152-
153143
**`--version`**
154144

155145
*Show the version.*
@@ -165,7 +155,7 @@ Print the quantiles of the values (TBD).
165155
math stats quantiles [<one-of-four>] [<custom-arg>] [<values>...] [--file=<file>] [--directory=<directory>] [--shell=<shell>] [--custom=<custom>] [--version] [--help]
166156
```
167157

168-
## Arguments
158+
## General
169159

170160
**`one-of-four`**
171161

@@ -178,37 +168,33 @@ math stats quantiles [<one-of-four>] [<custom-arg>] [<values>...] [--file=<f
178168
*A group of floating-point values to operate on.*
179169

180170

181-
## Flags
182-
183-
**`--version`**
184-
185-
*Show the version.*
171+
**`--file=\<file\>`**
186172

187173

188-
**`--help`**
174+
**`--directory=\<directory\>`**
189175

190-
*Show help information.*
191176

177+
**`--shell=\<shell\>`**
192178

193-
## Optionals
194179

195-
**`--file=\<file\>`**
180+
**`--custom=\<custom\>`**
196181

197182

198-
**`--directory=\<directory\>`**
183+
**`--version`**
199184

185+
*Show the version.*
200186

201-
**`--shell=\<shell\>`**
202187

188+
**`--help`**
203189

204-
**`--custom=\<custom\>`**## math.help
190+
*Show help information.*## math.help
205191

206192
Show subcommand help information.
207193

208194
```
209195
math help [<subcommands>...]
210196
```
211197

212-
## Arguments
198+
## General
213199

214200
**`subcommands`**

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testRepeatDoccReference().md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repeat [--count=<count>] [--include-counter] <phrase> [--help]
2525
*Show help information.*
2626

2727

28-
## Optionals
28+
## Options
2929

3030
**`--count=\<count\>`**
3131

@@ -42,6 +42,6 @@ Show subcommand help information.
4242
repeat help [<subcommands>...]
4343
```
4444

45-
## Arguments
45+
## General
4646

4747
**`subcommands`**

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testRollDoccReference().md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ roll [--times=<n>] [--sides=<m>] [--seed=<seed>] [--verbose] [--help]
1818
*Show help information.*
1919

2020

21-
## Optionals
21+
## Options
2222

2323
**`--times=\<n\>`**
2424

@@ -47,6 +47,6 @@ Show subcommand help information.
4747
roll help [<subcommands>...]
4848
```
4949

50-
## Arguments
50+
## General
5151

5252
**`subcommands`**

Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"kind" : "long",
3030
"name" : "enumerated-option"
3131
},
32-
"sectionTitle" : "Optionals",
3332
"shouldDisplay" : true,
3433
"valueName" : "enumerated-option"
3534
},
@@ -62,7 +61,6 @@
6261
"kind" : "long",
6362
"name" : "enumerated-option-with-default-value"
6463
},
65-
"sectionTitle" : "Optionals",
6664
"shouldDisplay" : true,
6765
"valueName" : "enumerated-option-with-default-value"
6866
},
@@ -80,7 +78,6 @@
8078
"kind" : "long",
8179
"name" : "no-help-option"
8280
},
83-
"sectionTitle" : "Optionals",
8481
"shouldDisplay" : true,
8582
"valueName" : "no-help-option"
8683
},
@@ -99,7 +96,6 @@
9996
"kind" : "long",
10097
"name" : "int-option"
10198
},
102-
"sectionTitle" : "Optionals",
10399
"shouldDisplay" : true,
104100
"valueName" : "int-option"
105101
},
@@ -119,15 +115,13 @@
119115
"kind" : "long",
120116
"name" : "int-option-with-default-value"
121117
},
122-
"sectionTitle" : "Optionals",
123118
"shouldDisplay" : true,
124119
"valueName" : "int-option-with-default-value"
125120
},
126121
{
127122
"isOptional" : false,
128123
"isRepeating" : false,
129124
"kind" : "positional",
130-
"sectionTitle" : "Arguments",
131125
"shouldDisplay" : true,
132126
"valueName" : "arg"
133127
},
@@ -136,7 +130,6 @@
136130
"isOptional" : false,
137131
"isRepeating" : false,
138132
"kind" : "positional",
139-
"sectionTitle" : "Arguments",
140133
"shouldDisplay" : true,
141134
"valueName" : "arg-with-help"
142135
},
@@ -146,7 +139,6 @@
146139
"isOptional" : true,
147140
"isRepeating" : false,
148141
"kind" : "positional",
149-
"sectionTitle" : "Arguments",
150142
"shouldDisplay" : true,
151143
"valueName" : "arg-with-default-value"
152144
},
@@ -169,7 +161,6 @@
169161
"kind" : "long",
170162
"name" : "help"
171163
},
172-
"sectionTitle" : "Flags",
173164
"shouldDisplay" : true,
174165
"valueName" : "help"
175166
}
@@ -184,7 +175,6 @@
184175
"isOptional" : true,
185176
"isRepeating" : true,
186177
"kind" : "positional",
187-
"sectionTitle" : "Arguments",
188178
"shouldDisplay" : true,
189179
"valueName" : "subcommands"
190180
},
@@ -210,7 +200,6 @@
210200
"kind" : "long",
211201
"name" : "help"
212202
},
213-
"sectionTitle" : "Flags",
214203
"shouldDisplay" : false,
215204
"valueName" : "help"
216205
}

Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"kind" : "long",
5757
"name" : "help"
5858
},
59-
"sectionTitle" : "Flags",
6059
"shouldDisplay" : true,
6160
"valueName" : "help"
6261
}
@@ -71,7 +70,6 @@
7170
"isOptional" : true,
7271
"isRepeating" : true,
7372
"kind" : "positional",
74-
"sectionTitle" : "Arguments",
7573
"shouldDisplay" : true,
7674
"valueName" : "subcommands"
7775
},
@@ -97,7 +95,6 @@
9795
"kind" : "long",
9896
"name" : "help"
9997
},
100-
"sectionTitle" : "Flags",
10198
"shouldDisplay" : false,
10299
"valueName" : "help"
103100
}

0 commit comments

Comments
 (0)