Skip to content

Commit a01856b

Browse files
authored
Enable Documentation check (apple#708)
Enables the documentation check from the swiftlang soundness workflow and resolves errors/notes emitted by the check. Fixes: apple#704
1 parent 33acc79 commit a01856b

File tree

14 files changed

+42
-42
lines changed

14 files changed

+42
-42
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ jobs:
99
name: Soundness
1010
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
1111
with:
12-
docs_check_enabled: false # bug: https://github.com/apple/swift-argument-parser/issues/704
1312
format_check_enabled: false # bug: https://github.com/apple/swift-argument-parser/issues/702
1413
license_header_check_enabled: false # feature: https://github.com/swiftlang/github-workflows/issues/78
1514
license_header_check_project_name: "Swift Argument Parser" # bug: https://github.com/swiftlang/github-workflows/issues/76

Sources/ArgumentParser/Documentation.docc/Articles/CustomizingCommandHelp.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ hello!
5959
...
6060
```
6161

62-
## Modifying the Help Flag Names
62+
### Modifying the Help Flag Names
6363

6464
Users can see the help screen for a command by passing either the `-h` or the `--help` flag, by default. If you need to use one of those flags for another purpose, you can provide alternative names when configuring a root command.
6565

@@ -123,11 +123,11 @@ OPTIONS:
123123
-?, --help Show help information.
124124
```
125125

126-
## Hiding Commands
126+
### Hiding Commands
127127

128128
You may not want to show every one of your command as part of your command-line interface. To render a command invisible (but still usable), pass `shouldDisplay: false` to the ``CommandConfiguration`` initializer.
129129

130-
## Generating Help Text Programmatically
130+
### Generating Help Text Programmatically
131131

132132
The help screen is automatically shown to users when they call your command with the help flag. You can generate the same text from within your program by calling the `helpMessage()` method.
133133

Sources/ArgumentParser/Documentation.docc/Articles/CustomizingHelp.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OPTIONS:
3535
-h, --help Show help information.
3636
```
3737

38-
## Customizing Help for Arguments
38+
### Customizing Help for Arguments
3939

4040
For more control over the help text, pass an ``ArgumentHelp`` instance instead of a string literal. The `ArgumentHelp` type can include an abstract (which is what the string literal becomes), a discussion, a value name to use in the usage string, and a visibility level for that argument.
4141

@@ -74,7 +74,7 @@ OPTIONS:
7474
-h, --help Show help information.
7575
```
7676

77-
## Enumerating Possible Values
77+
### Enumerating Possible Values
7878

7979
When an argument or option has a fixed set of possible values, listing these values in the help screen can simplify use of your tool. You can customize the displayed set of values for custom ``ExpressibleByArgument`` types by implementing ``ExpressibleByArgument/allValueStrings``. Despite the name, ``ExpressibleByArgument/allValueStrings`` does _not_ need to be an exhaustive list of possible values.
8080

@@ -113,9 +113,9 @@ OPTIONS:
113113
-h, --help Show help information.
114114
```
115115

116-
### Deriving Possible Values
116+
#### Deriving Possible Values
117117

118-
ExpressibleByArgument types that conform to ``CaseIterable`` do not need to manually specify ``ExpressibleByArgument/allValueStrings``. Instead, a list of possible values is derived from the type's cases, as in this updated example:
118+
ExpressibleByArgument types that conform to `CaseIterable` do not need to manually specify ``ExpressibleByArgument/allValueStrings``. Instead, a list of possible values is derived from the type's cases, as in this updated example:
119119

120120
```swift
121121
enum Fruit: String, CaseIterable, ExpressibleByArgument {
@@ -148,9 +148,9 @@ OPTIONS:
148148
-h, --help Show help information.
149149
```
150150

151-
For an ``ExpressibleByArgument`` and ``CaseIterable`` type with many cases, you may still want to implement ``ExpressibleByArgument/allValueStrings`` to avoid an overly long list of values appearing in the help screen. For these types it is recommended to include the most common possible values.
151+
For an ``ExpressibleByArgument`` and `CaseIterable` type with many cases, you may still want to implement ``ExpressibleByArgument/allValueStrings`` to avoid an overly long list of values appearing in the help screen. For these types it is recommended to include the most common possible values.
152152

153-
## Controlling Argument Visibility
153+
### Controlling Argument Visibility
154154

155155
You can specify the visibility of any argument, option, or flag.
156156

@@ -218,7 +218,7 @@ OPTIONS:
218218
-h, --help Show help information.
219219
```
220220

221-
## Grouping Arguments in the Help Screen
221+
### Grouping Arguments in the Help Screen
222222

223223
When you provide a title in an `@OptionGroup` declaration, that type's properties are grouped together under your title in the help screen. For example, this command bundles similar arguments together under a "Build Options" title:
224224

Sources/ArgumentParser/Documentation.docc/Articles/DeclaringArguments.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Your lucky numbers are:
8989
1 2 3
9090
```
9191

92-
## Customizing option and flag names
92+
### Customizing option and flag names
9393

9494
By default, options and flags derive the name that you use on the command line from the name of the property, such as `--count` and `--index`. Camel-case names are converted to lowercase with hyphen-separated words, like `--strip-whitespace`.
9595

@@ -132,7 +132,7 @@ struct Example: ParsableCommand {
132132
**Note:** You can also pass `withSingleDash: true` to `.customLong` to create a single-dash flag or option, such as `-verbose`. Use this name specification only when necessary, such as when migrating a legacy command-line interface. Using long names with a single-dash prefix can lead to ambiguity with combined short names: it may not be obvious whether `-file` is a single option or the combination of the four short options `-f`, `-i`, `-l`, and `-e`.
133133

134134

135-
## Parsing custom types
135+
### Parsing custom types
136136

137137
Arguments and options can be parsed from any type that conforms to the ``ExpressibleByArgument`` protocol. Standard library integer and floating-point types, strings, and Booleans all conform to `ExpressibleByArgument`.
138138

@@ -201,7 +201,7 @@ struct Example: ParsableCommand {
201201

202202
Throw an error from the `transform` function to indicate that the user provided an invalid value for that type. See <doc:Validation> for more about customizing `transform` function errors.
203203

204-
## Using flag inversions, enumerations, and counts
204+
### Using flag inversions, enumerations, and counts
205205

206206
Flags are most frequently used for `Bool` properties. You can generate a `true`/`false` pair of flags by specifying a flag inversion:
207207

@@ -288,7 +288,7 @@ Verbosity level: 4
288288
```
289289

290290

291-
## Specifying default values
291+
### Specifying default values
292292

293293
You can specify default values for almost all supported argument, option, and flag types using normal property initialization syntax:
294294

@@ -327,7 +327,7 @@ If a default is not specified, the user must provide a value for that argument/o
327327
You must also always specify a default of `false` for a non-optional `Bool` flag, as in the example above. This makes the behavior consistent with both normal Swift properties (which either must be explicitly initialized or optional to initialize a `struct`/`class` containing them) and the other property types.
328328

329329

330-
## Specifying a parsing strategy
330+
### Specifying a parsing strategy
331331

332332
When parsing a list of command-line inputs, `ArgumentParser` distinguishes between dash-prefixed keys and un-prefixed values. When looking for the value for a key, only an un-prefixed value will be selected by default.
333333

@@ -358,7 +358,7 @@ Usage: example [--verbose] --name <name> [<file>]
358358

359359
Parsing options as arrays is similar — only adjacent key-value pairs are recognized by default.
360360

361-
### Alternative single-value parsing strategies
361+
#### Alternative single-value parsing strategies
362362

363363
You can change this behavior by providing a different parsing strategy in the `@Option` initializer. **Be careful when selecting any of the alternative parsing strategies** — they may lead your command-line tool to have unexpected behavior for users!
364364

@@ -376,7 +376,7 @@ The `.scanningForValue` strategy, on the other hand, looks ahead in the list of
376376
Verbose: true, name: Tomás, file: none
377377
```
378378

379-
### Alternative array parsing strategies
379+
#### Alternative array parsing strategies
380380

381381
The default strategy for parsing options as arrays is to read each value from a key-value pair. For example, this command expects zero or more input file names:
382382

@@ -427,7 +427,7 @@ Verbose: true, files: ["file1.swift", "file2.swift"]
427427
Verbose: false, files: ["file1.swift", "file2.swift", "--verbose"]
428428
```
429429

430-
### Alternative positional argument parsing strategies
430+
#### Alternative positional argument parsing strategies
431431

432432
The default strategy for parsing arrays of positional arguments is to ignore all dash-prefixed command-line inputs. For example, this command accepts a `--verbose` flag and a list of file names as positional arguments:
433433

@@ -469,7 +469,7 @@ Verbose: true, files: ["file1.swift", "file2.swift", "--other"]
469469
Verbose: false, files: ["--", "--verbose", "file1.swift", "file2.swift", "--other"]
470470
```
471471

472-
### Ignoring unknown arguments
472+
#### Ignoring unknown arguments
473473

474474
Different versions of a CLI tool may have full or partial sets of supported flags and options.
475475

Sources/ArgumentParser/Documentation.docc/Articles/ExperimentalFeatures.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Command-line programs built using `ArgumentParser` may include some built-in exp
88

99
If you have any feedback on experimental features, please [open a GitHub issue][issue].
1010

11-
## List of Experimental Features
11+
### List of Experimental Features
1212

1313
| Name | Description | related PRs | Version |
1414
| ------------- | ------------- | ------------- | ------------- |

Sources/ArgumentParser/Documentation.docc/Articles/GettingStarted.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Learn to set up and customize a simple command-line tool.
66

77
This guide walks through building an example command. You'll learn about the different tools that `ArgumentParser` provides for defining a command's options, customizing the interface, and providing help text for your user.
88

9-
## Adding ArgumentParser as a Dependency
9+
### Adding ArgumentParser as a Dependency
1010

1111
Let's write a tool called `count` that reads an input file, counts the words, and writes the result to an output file.
1212

@@ -31,7 +31,7 @@ let package = Package(
3131
)
3232
```
3333

34-
## Building Our First Command
34+
### Building Our First Command
3535

3636
Once we've built the `count` tool, we'll be able to run it like this:
3737

@@ -69,7 +69,7 @@ Finally, the `Count` command is designated as the program's entry point by apply
6969

7070
> Note: The Swift compiler uses either the type marked with `@main` or a `main.swift` file as the entry point for an executable program. You can use either one, but not both — rename your `main.swift` file to the name of the command when you add `@main`. In this case, rename the file to `Count.swift`.
7171
72-
## Working with Named Options
72+
### Working with Named Options
7373

7474
Our `count` tool may have a usability problem — it's not immediately clear whether a user should provide the input file first, or the output file. Instead of using positional arguments for our two inputs, let's specify that they should be labeled options:
7575

@@ -106,7 +106,7 @@ This interface has a trade-off for the users of our `count` tool: With `@Argumen
106106
Counting words in 'readme.md' and writing the result into 'readme.counts'.
107107
```
108108

109-
## Adding a Flag
109+
### Adding a Flag
110110

111111
Next, we want to add a `--verbose` flag to our tool, and only print the message if the user specifies that option:
112112

@@ -142,7 +142,7 @@ struct Count: ParsableCommand {
142142
The `@Flag` property wrapper denotes a command-line input that looks like `--name`, deriving its name from the name of your property. Flags are most frequently used for Boolean values, like the `verbose` property here.
143143

144144

145-
## Using Custom Names
145+
### Using Custom Names
146146

147147
We can customize the names of our options and add an alternative to the `verbose` flag so that users can specify `-v` instead of `--verbose`. The new interface will look like this:
148148

@@ -175,7 +175,7 @@ struct Count: ParsableCommand {
175175

176176
The default name specification is `.long`, which uses a property's name with a two-dash prefix. `.short` uses only the first letter of a property's name with a single-dash prefix, and allows combining groups of short options. You can specify custom short and long names with the `.customShort(_:)` and `.customLong(_:)` methods, respectively, or use the combined `.shortAndLong` property to specify the common case of both the short and long derived names.
177177

178-
## Providing Help
178+
### Providing Help
179179

180180
`ArgumentParser` automatically generates help for any command when a user provides the `-h` or `--help` flags:
181181

@@ -222,7 +222,7 @@ OPTIONS:
222222
223223
```
224224

225-
## The Complete Utility
225+
### The Complete Utility
226226

227227
As promised, here's the complete `count` command, for your experimentation:
228228

@@ -289,7 +289,7 @@ struct RuntimeError: Error, CustomStringConvertible {
289289
```
290290

291291

292-
## Next Steps … Swift concurrency
292+
### Next Steps … Swift concurrency
293293

294294
`ArgumentParser` supports Swift concurrency, notably `async` renditions of `run`. If you use `async` rendition of `run`, conform to `AsyncParsableCommand` instead of `ParsableCommand`.
295295

Sources/ArgumentParser/Documentation.docc/Articles/ManualParsing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Provide your own array of command-line inputs or work directly with parsed comma
66

77
For most programs, denoting the root command type as `@main` is all that's necessary. As the program's entry point, that type parses the command-line arguments to find the correct command from your tree of nested subcommands, instantiates and validates the result, and executes the chosen command. For more control, however, you can perform each of those steps manually.
88

9-
## Parsing Arguments
9+
### Parsing Arguments
1010

1111
For simple Swift scripts, and for those who prefer a straight-down-the-left-edge-of-the-screen scripting style, you can define a single ``ParsableArguments`` type to parse explicitly from the command-line arguments.
1212

@@ -47,7 +47,7 @@ let chosen = options.elements
4747
print(chosen.joined(separator: "\n"))
4848
```
4949

50-
## Parsing Commands
50+
### Parsing Commands
5151

5252
Manually parsing commands is a little more complex than parsing a simple `ParsableArguments` type. The result of parsing from a tree of subcommands may be of a different type than the root of the tree, so the static ``ParsableCommand/parseAsRoot(_:)`` method returns a type-erased ``ParsableCommand``.
5353

@@ -80,7 +80,7 @@ You chose to do something else.
8080
1050
8181
```
8282

83-
## Providing Command-Line Input
83+
### Providing Command-Line Input
8484

8585
All of the parsing methods — `parse()`, `parseOrExit()`, and `parseAsRoot()` — can optionally take an array of command-line inputs as an argument. You can use this capability to test your commands, to perform pre-parse filtering of the command-line arguments, or to manually execute commands from within the same or another target.
8686

Sources/ArgumentParser/Documentation.docc/Articles/Validation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ howdy
5757
hey
5858
```
5959

60-
## Handling Post-Validation Errors
60+
### Handling Post-Validation Errors
6161

6262
The ``ValidationError`` type is a special `ArgumentParser` error — a validation error's message is always accompanied by an appropriate usage string. You can throw other errors, from either the `validate()` or `run()` method to indicate that something has gone wrong that isn't validation-specific. Errors that conform to `CustomStringConvertible` or `LocalizedError` provide the best experience for users.
6363

@@ -103,7 +103,7 @@ struct Example: ParsableCommand {
103103
}
104104
```
105105

106-
## Handling Transform Errors
106+
### Handling Transform Errors
107107

108108
During argument and option parsing, you can use a closure to transform the command line strings to custom types. If this transformation fails, you can throw a `ValidationError`; its `message` property will be displayed to the user.
109109

Sources/ArgumentParser/Documentation.docc/Extensions/CommandConfiguration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Creating a Configuration
66

7-
- ``init(commandName:abstract:usage:discussion:version:shouldDisplay:subcommands:defaultSubcommand:helpNames:aliases:)``
7+
- ``init(commandName:abstract:usage:discussion:version:shouldDisplay:subcommands:groupedSubcommands:defaultSubcommand:helpNames:aliases:)``
88

99
### Customizing the Help Screen
1010

Sources/ArgumentParser/Parsable Properties/Argument.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ extension Argument {
618618
/// Creates a property that reads an array from zero or more arguments.
619619
///
620620
/// - Parameters:
621-
/// - initial: A default value to use for this property.
621+
/// - wrappedValue: A default value to use for this property.
622622
/// - parsingStrategy: The behavior to use when parsing multiple values from
623623
/// the command-line arguments.
624624
/// - help: Information about how to use this argument.

Sources/ArgumentParser/Parsable Properties/Errors.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public struct CleanExit: Error, CustomStringConvertible {
8282
///
8383
/// - Parameter command: The command type to offer help for, if different
8484
/// from the root command.
85-
public static func helpRequest(_ type: ParsableCommand.Type? = nil) -> CleanExit {
86-
self.init(base: .helpRequest(type))
85+
public static func helpRequest(_ command: ParsableCommand.Type? = nil) -> CleanExit {
86+
self.init(base: .helpRequest(command))
8787
}
8888

8989
/// Treat this error as a clean exit with the given message.

Sources/ArgumentParser/Parsable Properties/Flag.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ extension Flag where Value == Bool {
345345
///
346346
/// - Parameters:
347347
/// - name: A specification for what names are allowed for this flag.
348-
/// - wrappedValue: A default value to use for this property, provided implicitly by the compiler during property wrapper initialization.
349348
/// - inversion: The method for converting this flag's name into an on/off pair.
350349
/// - exclusivity: The behavior to use when an on/off pair of flags is specified.
351350
/// - help: Information about how to use this flag.
@@ -580,7 +579,8 @@ extension Flag {
580579
/// This property has an empty array as its default value.
581580
///
582581
/// - Parameters:
583-
/// - name: A specification for what names are allowed for this flag.
582+
/// - wrappedValue: A default value to use for this property, provided
583+
// implicitly by the compiler during property wrapper initialization.
584584
/// - help: Information about how to use this flag.
585585
public init<Element>(
586586
wrappedValue: [Element],

Sources/ArgumentParser/Parsable Properties/Option.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,6 @@ extension Option {
706706
/// - help: Information about how to use this option.
707707
/// - completion: The type of command-line completion provided for this
708708
/// option.
709-
/// - transform: A closure that converts a string into this property's
710-
/// element type, or else throws an error.
711709
public init<T>(
712710
wrappedValue: Array<T>,
713711
name: NameSpecification = .long,

Sources/ArgumentParser/Parsable Types/ParsableCommand.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ extension ParsableCommand {
116116
/// Returns the usage text for the given subcommand of this command.
117117
///
118118
/// - Parameters:
119+
/// - subcommand: The subcommand to generate the help screen for.
120+
/// `subcommand` must be declared in the subcommand tree of this
121+
/// command.
119122
/// - includeHidden: Include hidden help information in the generated
120123
/// message.
121124
/// - Returns: The usage text for this type.

0 commit comments

Comments
 (0)