Skip to content

Commit

Permalink
Fix generate-manual plugin authors argument (#471)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
rauhul committed Aug 25, 2022
1 parent 898d1ae commit 4b93f3e
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Plugins/GenerateManualPlugin/GenerateManualPlugin.swift
Expand Up @@ -85,7 +85,7 @@ struct GenerateManualPlugin: CommandPlugin {
outputDirectory.string
]
generationToolArguments.append(
contentsOf: extractor.unextractedOptionsOrFlags)
contentsOf: extractor.remainingArguments)

// Spawn generation tool.
try generationToolFile.exec(arguments: generationToolArguments)
Expand Down
Expand Up @@ -46,5 +46,5 @@ extension GenerateManualPluginError: CustomStringConvertible {
}

extension GenerateManualPluginError: LocalizedError {
var localizedDescription: String { self.description }
var errorDescription: String? { self.description }
}
Expand Up @@ -48,6 +48,7 @@ final class CountLinesGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down Expand Up @@ -89,6 +90,7 @@ final class CountLinesGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down
Expand Up @@ -110,6 +110,7 @@ final class MathGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down Expand Up @@ -150,6 +151,7 @@ final class MathGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down Expand Up @@ -186,6 +188,7 @@ final class MathGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down Expand Up @@ -222,6 +225,7 @@ final class MathGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down Expand Up @@ -257,6 +261,7 @@ final class MathGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down Expand Up @@ -293,6 +298,7 @@ final class MathGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down Expand Up @@ -326,6 +332,7 @@ final class MathGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down Expand Up @@ -379,6 +386,7 @@ final class MathGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down
Expand Up @@ -45,6 +45,7 @@ final class RepeatGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down Expand Up @@ -85,6 +86,7 @@ final class RepeatGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down
Expand Up @@ -50,6 +50,7 @@ final class RollDiceGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down Expand Up @@ -95,6 +96,7 @@ final class RollDiceGenerateManualTests: XCTestCase {
.An -nosplit
.An "Jane Appleseed" ,
.Mt johnappleseed@apple.com ,
and
.An -nosplit
.An "The Appleseeds"
.Ao
Expand Down
22 changes: 20 additions & 2 deletions Tools/generate-manual/DSL/Authors.swift
Expand Up @@ -21,8 +21,26 @@ struct Authors: MDocComponent {
"The"
MDocMacro.DocumentName()
"reference was written by"
ForEach(authors) { author, last in
Author(author: author, trailing: last ? "." : ",")
ForEach(authors) { author, index in
switch index {
case authors.count - 2 where authors.count > 2:
Author(
author: author,
trailing: ",")
"and"
case authors.count - 2:
Author(
author: author,
trailing: "and")
case authors.count - 1:
Author(
author: author,
trailing: ".")
default:
Author(
author: author,
trailing: ",")
}
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions Tools/generate-manual/DSL/Core/ForEach.swift
Expand Up @@ -11,24 +11,22 @@

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

init(_ items: C, @MDocBuilder builder: @escaping (C.Element, Bool) -> MDocComponent) {
init(_ items: C, @MDocBuilder builder: @escaping (C.Element, C.Index) -> MDocComponent) {
self.items = items
self.builder = builder
}

var body: MDocComponent {
guard !items.isEmpty else { return Empty() }
var currentIndex = items.startIndex
var last = false
var components = [MDocComponent]()
repeat {
while currentIndex < items.endIndex {
let item = items[currentIndex]
components.append(builder(item, currentIndex))
currentIndex = items.index(after: currentIndex)
last = currentIndex == items.endIndex
components.append(builder(item, last))
} while !last
}
return Container(children: components)
}
}
5 changes: 3 additions & 2 deletions Tools/generate-manual/DSL/SeeAlso.swift
Expand Up @@ -23,9 +23,10 @@ struct SeeAlso: MDocComponent {

var body: MDocComponent {
Section(title: "see also") {
ForEach(references) { reference, isLast in
ForEach(references) { reference, index in
MDocMacro.CrossManualReference(title: reference, section: section)
.withUnsafeChildren(nodes: isLast ? [] : [","])
.withUnsafeChildren(
nodes: index == references.count - 1 ? [] : [","])
}
}
}
Expand Down

0 comments on commit 4b93f3e

Please sign in to comment.