Skip to content

Commit 5649a38

Browse files
authored
Add subcommand abstracts to single-page manuals (#552)
- Fixes a bug where signle-page manuals did not include subcommand abstracts because the DSL logic did not take to account root commands vs subcommands. This change adds a "root" property to the DSL element to allow for styling differences in the two cases.
1 parent fee6933 commit 5649a38

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Tests/ArgumentParserGenerateManualTests/MathGenerateManualTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ final class MathGenerateManualTests: XCTestCase {
3535
.It Fl h , -help
3636
Show help information.
3737
.It Em add
38+
Print the sum of the values.
3839
.Bl -tag -width 6n
3940
.It Fl x , -hex-output
4041
Use hexadecimal notation for the result.
@@ -46,6 +47,7 @@ final class MathGenerateManualTests: XCTestCase {
4647
Show help information.
4748
.El
4849
.It Em multiply
50+
Print the product of the values.
4951
.Bl -tag -width 6n
5052
.It Fl x , -hex-output
5153
Use hexadecimal notation for the result.
@@ -57,12 +59,14 @@ final class MathGenerateManualTests: XCTestCase {
5759
Show help information.
5860
.El
5961
.It Em stats
62+
Calculate descriptive statistics.
6063
.Bl -tag -width 6n
6164
.It Fl -version
6265
Show the version.
6366
.It Fl h , -help
6467
Show help information.
6568
.It Em average
69+
Print the average of the values.
6670
.Bl -tag -width 6n
6771
.It Fl -kind Ar kind
6872
The kind of average to provide.
@@ -74,6 +78,7 @@ final class MathGenerateManualTests: XCTestCase {
7478
Show help information.
7579
.El
7680
.It Em stdev
81+
Print the standard deviation of the values.
7782
.Bl -tag -width 6n
7883
.It Ar values...
7984
A group of floating-point values to operate on.
@@ -83,6 +88,7 @@ final class MathGenerateManualTests: XCTestCase {
8388
Show help information.
8489
.El
8590
.It Em quantiles
91+
Print the quantiles of the values (TBD).
8692
.Bl -tag -width 6n
8793
.It Ar one-of-four
8894
.It Ar custom-arg

Tools/generate-manual/DSL/Document.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct Document: MDocComponent {
2727
if multiPage {
2828
MultiPageDescription(command: command)
2929
} else {
30-
SinglePageDescription(command: command)
30+
SinglePageDescription(command: command, root: true)
3131
}
3232
Exit(section: section)
3333
if multiPage {

Tools/generate-manual/DSL/SinglePageDescription.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import ArgumentParserToolInfo
1414

1515
struct SinglePageDescription: MDocComponent {
1616
var command: CommandInfoV0
17+
var root: Bool
1718

1819
var body: MDocComponent {
1920
Section(title: "description") {
@@ -23,6 +24,14 @@ struct SinglePageDescription: MDocComponent {
2324

2425
@MDocBuilder
2526
var core: MDocComponent {
27+
if !root, let abstract = command.abstract {
28+
abstract
29+
}
30+
31+
if !root, command.abstract != nil, command.discussion != nil {
32+
MDocMacro.ParagraphBreak()
33+
}
34+
2635
if let discussion = command.discussion {
2736
discussion
2837
}
@@ -46,7 +55,7 @@ struct SinglePageDescription: MDocComponent {
4655

4756
for subcommand in command.subcommands ?? [] {
4857
MDocMacro.ListItem(title: MDocMacro.Emphasis(arguments: [subcommand.commandName]))
49-
SinglePageDescription(command: subcommand).core
58+
SinglePageDescription(command: subcommand, root: false).core
5059
}
5160
}
5261
}

0 commit comments

Comments
 (0)