Skip to content

Commit

Permalink
Default to single page manuals (#472)
Browse files Browse the repository at this point in the history
- Changes the generate-manual --single-page argument to --multi-page, so
  generate-manual with create a single manual page with all subcommand
  information by default instead of many distinct files.
  • Loading branch information
rauhul committed Aug 26, 2022
1 parent 4b93f3e commit e978a38
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Sources/ArgumentParserTestHelpers/TestHelpers.swift
Expand Up @@ -325,7 +325,7 @@ extension XCTest {
}

public func AssertGenerateManual(
singlePage: Bool,
multiPage: Bool,
command: String,
expected: String,
file: StaticString = #file,
Expand All @@ -341,8 +341,8 @@ extension XCTest {
"--authors", "The Appleseeds<appleseeds@apple.com>",
"--output-directory", "-",
]
if singlePage {
command.append("--single-page")
if multiPage {
command.append("--multi-page")
}
try AssertExecuteCommand(
command: command,
Expand Down
Expand Up @@ -17,7 +17,7 @@ import ArgumentParserTestHelpers
final class CountLinesGenerateManualTests: XCTestCase {
func testCountLines_SinglePageManual() throws {
guard #available(macOS 12, *) else { return }
try AssertGenerateManual(singlePage: true, command: "count-lines", expected: #"""
try AssertGenerateManual(multiPage: false, command: "count-lines", expected: #"""
.\" "Generated by swift-argument-parser"
.Dd May 12, 1996
.Dt COUNT-LINES 9
Expand Down Expand Up @@ -59,7 +59,7 @@ final class CountLinesGenerateManualTests: XCTestCase {

func testCountLines_MultiPageManual() throws {
guard #available(macOS 12, *) else { return }
try AssertGenerateManual(singlePage: false, command: "count-lines", expected: #"""
try AssertGenerateManual(multiPage: true, command: "count-lines", expected: #"""
.\" "Generated by swift-argument-parser"
.Dd May 12, 1996
.Dt COUNT-LINES 9
Expand Down
Expand Up @@ -15,7 +15,7 @@ import ArgumentParserTestHelpers

final class MathGenerateManualTests: XCTestCase {
func testMath_SinglePageManual() throws {
try AssertGenerateManual(singlePage: true, command: "math", expected: #"""
try AssertGenerateManual(multiPage: false, command: "math", expected: #"""
.\" "Generated by swift-argument-parser"
.Dd May 12, 1996
.Dt MATH 9
Expand Down Expand Up @@ -120,7 +120,7 @@ final class MathGenerateManualTests: XCTestCase {
}

func testMath_MultiPageManual() throws {
try AssertGenerateManual(singlePage: false, command: "math", expected: #"""
try AssertGenerateManual(multiPage: true, command: "math", expected: #"""
.\" "Generated by swift-argument-parser"
.Dd May 12, 1996
.Dt MATH 9
Expand Down
Expand Up @@ -14,7 +14,7 @@ import ArgumentParserTestHelpers

final class RepeatGenerateManualTests: XCTestCase {
func testMath_SinglePageManual() throws {
try AssertGenerateManual(singlePage: true, command: "repeat", expected: #"""
try AssertGenerateManual(multiPage: false, command: "repeat", expected: #"""
.\" "Generated by swift-argument-parser"
.Dd May 12, 1996
.Dt REPEAT 9
Expand Down Expand Up @@ -55,7 +55,7 @@ final class RepeatGenerateManualTests: XCTestCase {
}

func testMath_MultiPageManual() throws {
try AssertGenerateManual(singlePage: false, command: "repeat", expected: #"""
try AssertGenerateManual(multiPage: true, command: "repeat", expected: #"""
.\" "Generated by swift-argument-parser"
.Dd May 12, 1996
.Dt REPEAT 9
Expand Down
Expand Up @@ -14,7 +14,7 @@ import ArgumentParserTestHelpers

final class RollDiceGenerateManualTests: XCTestCase {
func testRollDice_SinglePageManual() throws {
try AssertGenerateManual(singlePage: true, command: "roll", expected: #"""
try AssertGenerateManual(multiPage: false, command: "roll", expected: #"""
.\" "Generated by swift-argument-parser"
.Dd May 12, 1996
.Dt ROLL 9
Expand Down Expand Up @@ -60,7 +60,7 @@ final class RollDiceGenerateManualTests: XCTestCase {
}

func testRollDice_MultiPageManual() throws {
try AssertGenerateManual(singlePage: false, command: "roll", expected: #"""
try AssertGenerateManual(multiPage: true, command: "roll", expected: #"""
.\" "Generated by swift-argument-parser"
.Dd May 12, 1996
.Dt ROLL 9
Expand Down
10 changes: 5 additions & 5 deletions Tools/generate-manual/DSL/Document.swift
Expand Up @@ -14,7 +14,7 @@ import ArgumentParserToolInfo
import Foundation

struct Document: MDocComponent {
var singlePage: Bool
var multiPage: Bool
var date: Date
var section: Int
var authors: [AuthorArgument]
Expand All @@ -24,13 +24,13 @@ struct Document: MDocComponent {
Preamble(date: date, section: section, command: command)
Name(command: command)
Synopsis(command: command)
if singlePage {
SinglePageDescription(command: command)
} else {
if multiPage {
MultiPageDescription(command: command)
} else {
SinglePageDescription(command: command)
}
Exit(section: section)
if !singlePage {
if multiPage {
SeeAlso(section: section, command: command)
}
Authors(authors: authors)
Expand Down
10 changes: 5 additions & 5 deletions Tools/generate-manual/GenerateManual.swift
Expand Up @@ -29,8 +29,8 @@ struct GenerateManual: ParsableCommand {
@Argument(help: "Tool to generate manual for.")
var tool: String

@Flag(help: "Generate a single page with information for all subcommands.")
var singlePage = false
@Flag(help: "Generate a separate manual for each subcommand.")
var multiPage = false

@Option(name: .long, help: "Override the creation date of the manual. Format: 'yyyy-mm-dd'.")
var date: Date = Date()
Expand All @@ -46,7 +46,7 @@ struct GenerateManual: ParsableCommand {

func validate() throws {
// Only man pages 1 through 9 are valid.
if !(1...9).contains(section) {
guard (1...9).contains(section) else {
throw ValidationError("Invalid manual section passed to --section")
}

Expand Down Expand Up @@ -106,7 +106,7 @@ struct GenerateManual: ParsableCommand {

func generatePages(from command: CommandInfoV0, savingTo directory: URL?) throws {
let document = Document(
singlePage: singlePage,
multiPage: multiPage,
date: date,
section: section,
authors: authors,
Expand All @@ -121,7 +121,7 @@ struct GenerateManual: ParsableCommand {
print(page)
}

if !singlePage {
if multiPage {
for subcommand in command.subcommands ?? [] {
try generatePages(from: subcommand, savingTo: directory)
}
Expand Down

0 comments on commit e978a38

Please sign in to comment.