Skip to content

Commit 4b93f3e

Browse files
authored
Fix generate-manual plugin authors argument (#471)
- Fixes an issue where the --author option was passed without its value by the generate-manual plugin to the generate-manual tool resulting in plugin invocation failures or incorrect author information.
1 parent 898d1ae commit 4b93f3e

File tree

9 files changed

+44
-13
lines changed

9 files changed

+44
-13
lines changed

Plugins/GenerateManualPlugin/GenerateManualPlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct GenerateManualPlugin: CommandPlugin {
8585
outputDirectory.string
8686
]
8787
generationToolArguments.append(
88-
contentsOf: extractor.unextractedOptionsOrFlags)
88+
contentsOf: extractor.remainingArguments)
8989

9090
// Spawn generation tool.
9191
try generationToolFile.exec(arguments: generationToolArguments)

Plugins/GenerateManualPlugin/GenerateManualPluginError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ extension GenerateManualPluginError: CustomStringConvertible {
4646
}
4747

4848
extension GenerateManualPluginError: LocalizedError {
49-
var localizedDescription: String { self.description }
49+
var errorDescription: String? { self.description }
5050
}

Tests/ArgumentParserGenerateManualTests/CountLinesGenerateManualTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ final class CountLinesGenerateManualTests: XCTestCase {
4848
.An -nosplit
4949
.An "Jane Appleseed" ,
5050
51+
and
5152
.An -nosplit
5253
.An "The Appleseeds"
5354
.Ao
@@ -89,6 +90,7 @@ final class CountLinesGenerateManualTests: XCTestCase {
8990
.An -nosplit
9091
.An "Jane Appleseed" ,
9192
93+
and
9294
.An -nosplit
9395
.An "The Appleseeds"
9496
.Ao

Tests/ArgumentParserGenerateManualTests/MathGenerateManualTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ final class MathGenerateManualTests: XCTestCase {
110110
.An -nosplit
111111
.An "Jane Appleseed" ,
112112
113+
and
113114
.An -nosplit
114115
.An "The Appleseeds"
115116
.Ao
@@ -150,6 +151,7 @@ final class MathGenerateManualTests: XCTestCase {
150151
.An -nosplit
151152
.An "Jane Appleseed" ,
152153
154+
and
153155
.An -nosplit
154156
.An "The Appleseeds"
155157
.Ao
@@ -186,6 +188,7 @@ final class MathGenerateManualTests: XCTestCase {
186188
.An -nosplit
187189
.An "Jane Appleseed" ,
188190
191+
and
189192
.An -nosplit
190193
.An "The Appleseeds"
191194
.Ao
@@ -222,6 +225,7 @@ final class MathGenerateManualTests: XCTestCase {
222225
.An -nosplit
223226
.An "Jane Appleseed" ,
224227
228+
and
225229
.An -nosplit
226230
.An "The Appleseeds"
227231
.Ao
@@ -257,6 +261,7 @@ final class MathGenerateManualTests: XCTestCase {
257261
.An -nosplit
258262
.An "Jane Appleseed" ,
259263
264+
and
260265
.An -nosplit
261266
.An "The Appleseeds"
262267
.Ao
@@ -293,6 +298,7 @@ final class MathGenerateManualTests: XCTestCase {
293298
.An -nosplit
294299
.An "Jane Appleseed" ,
295300
301+
and
296302
.An -nosplit
297303
.An "The Appleseeds"
298304
.Ao
@@ -326,6 +332,7 @@ final class MathGenerateManualTests: XCTestCase {
326332
.An -nosplit
327333
.An "Jane Appleseed" ,
328334
335+
and
329336
.An -nosplit
330337
.An "The Appleseeds"
331338
.Ao
@@ -379,6 +386,7 @@ final class MathGenerateManualTests: XCTestCase {
379386
.An -nosplit
380387
.An "Jane Appleseed" ,
381388
389+
and
382390
.An -nosplit
383391
.An "The Appleseeds"
384392
.Ao

Tests/ArgumentParserGenerateManualTests/RepeatGenerateManualTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ final class RepeatGenerateManualTests: XCTestCase {
4545
.An -nosplit
4646
.An "Jane Appleseed" ,
4747
48+
and
4849
.An -nosplit
4950
.An "The Appleseeds"
5051
.Ao
@@ -85,6 +86,7 @@ final class RepeatGenerateManualTests: XCTestCase {
8586
.An -nosplit
8687
.An "Jane Appleseed" ,
8788
89+
and
8890
.An -nosplit
8991
.An "The Appleseeds"
9092
.Ao

Tests/ArgumentParserGenerateManualTests/RollDiceGenerateManualTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ final class RollDiceGenerateManualTests: XCTestCase {
5050
.An -nosplit
5151
.An "Jane Appleseed" ,
5252
53+
and
5354
.An -nosplit
5455
.An "The Appleseeds"
5556
.Ao
@@ -95,6 +96,7 @@ final class RollDiceGenerateManualTests: XCTestCase {
9596
.An -nosplit
9697
.An "Jane Appleseed" ,
9798
99+
and
98100
.An -nosplit
99101
.An "The Appleseeds"
100102
.Ao

Tools/generate-manual/DSL/Authors.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,26 @@ struct Authors: MDocComponent {
2121
"The"
2222
MDocMacro.DocumentName()
2323
"reference was written by"
24-
ForEach(authors) { author, last in
25-
Author(author: author, trailing: last ? "." : ",")
24+
ForEach(authors) { author, index in
25+
switch index {
26+
case authors.count - 2 where authors.count > 2:
27+
Author(
28+
author: author,
29+
trailing: ",")
30+
"and"
31+
case authors.count - 2:
32+
Author(
33+
author: author,
34+
trailing: "and")
35+
case authors.count - 1:
36+
Author(
37+
author: author,
38+
trailing: ".")
39+
default:
40+
Author(
41+
author: author,
42+
trailing: ",")
43+
}
2644
}
2745
}
2846
}

Tools/generate-manual/DSL/Core/ForEach.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,22 @@
1111

1212
struct ForEach<C>: MDocComponent where C: Collection {
1313
var items: C
14-
var builder: (C.Element, Bool) -> MDocComponent
14+
var builder: (C.Element, C.Index) -> MDocComponent
1515

16-
init(_ items: C, @MDocBuilder builder: @escaping (C.Element, Bool) -> MDocComponent) {
16+
init(_ items: C, @MDocBuilder builder: @escaping (C.Element, C.Index) -> MDocComponent) {
1717
self.items = items
1818
self.builder = builder
1919
}
2020

2121
var body: MDocComponent {
2222
guard !items.isEmpty else { return Empty() }
2323
var currentIndex = items.startIndex
24-
var last = false
2524
var components = [MDocComponent]()
26-
repeat {
25+
while currentIndex < items.endIndex {
2726
let item = items[currentIndex]
27+
components.append(builder(item, currentIndex))
2828
currentIndex = items.index(after: currentIndex)
29-
last = currentIndex == items.endIndex
30-
components.append(builder(item, last))
31-
} while !last
29+
}
3230
return Container(children: components)
3331
}
3432
}

Tools/generate-manual/DSL/SeeAlso.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ struct SeeAlso: MDocComponent {
2323

2424
var body: MDocComponent {
2525
Section(title: "see also") {
26-
ForEach(references) { reference, isLast in
26+
ForEach(references) { reference, index in
2727
MDocMacro.CrossManualReference(title: reference, section: section)
28-
.withUnsafeChildren(nodes: isLast ? [] : [","])
28+
.withUnsafeChildren(
29+
nodes: index == references.count - 1 ? [] : [","])
2930
}
3031
}
3132
}

0 commit comments

Comments
 (0)