Skip to content

Commit c769981

Browse files
authored
Update documentation (#602)
Update some documentation, mark some code samples as being Swift so that syntax highlighting works properly, and hide some other infrequently-used symbols by adding internal parameter name underscores.
1 parent 9eded54 commit c769981

File tree

13 files changed

+93
-99
lines changed

13 files changed

+93
-99
lines changed

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

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

55
### Single Arguments
66

7-
- ``init(help:completion:)-6mld0``
7+
- ``init(help:completion:)-6pqzn``
88
- ``init(help:completion:)-4p94d``
99
- ``init(help:completion:transform:)-3fjtc``
1010
- ``init(help:completion:transform:)-7yn32``
@@ -21,5 +21,4 @@
2121

2222
### Infrequently Used APIs
2323

24-
- ``init(from:)``
2524
- ``wrappedValue``

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,3 @@
2424
- ``version``
2525
- ``shouldDisplay``
2626

27-
### Deprecated APIs
28-
29-
- ``init(commandName:abstract:discussion:version:shouldDisplay:subcommands:defaultSubcommand:helpNames:)``
30-

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
### Infrequently Used APIs
2929

30-
- ``init(from:)``
3130
- ``wrappedValue``
3231

3332
### Supporting Types

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
### Single Options
66

77
- ``init(name:parsing:help:completion:)-7slrf``
8-
- ``init(name:parsing:help:completion:)-5k0ug``
8+
- ``init(name:parsing:help:completion:)-4yske``
99
- ``init(name:parsing:help:completion:transform:)-2wf44``
1010
- ``init(name:parsing:help:completion:transform:)-25g7b``
1111
- ``init(wrappedValue:name:parsing:help:completion:transform:)-2llve``
1212
- ``SingleValueParsingStrategy``
13-
- ``init(wrappedValue:name:parsing:help:completion:)-7xcum``
13+
- ``init(wrappedValue:name:parsing:help:completion:)-7ilku``
1414

1515
### Array Options
1616

@@ -22,11 +22,4 @@
2222

2323
### Infrequently Used APIs
2424

25-
- ``init(from:)``
2625
- ``wrappedValue``
27-
28-
### Deprecated APIs
29-
30-
- ``init(wrappedValue:name:parsing:completion:help:)``
31-
- ``init(wrappedValue:name:parsing:help:completion:)-4pl7h``
32-
- ``init(wrappedValue:name:parsing:help:completion:transform:)-6rqji``

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
### Infrequently Used APIs
1414

1515
- ``init()``
16-
- ``init(from:)``
1716
- ``wrappedValue``
1817
- ``description``
1918

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
### Handling Errors
2323

2424
- ``message(for:)``
25-
- ``fullMessage(for:)``
25+
- ``fullMessage(for:columns:)``
2626
- ``exitCode(for:)``
2727

2828
### Generating Completion Scripts
@@ -33,4 +33,3 @@
3333
### Infrequently Used APIs
3434

3535
- ``init()``
36-
- ``helpMessage(columns:)``

Sources/ArgumentParser/Parsable Properties/Argument.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@
2121
/// argument is required, while `greeting` is optional because it has a default
2222
/// value.
2323
///
24-
/// @main
25-
/// struct Greet: ParsableCommand {
26-
/// @Argument var name: String
27-
/// @Argument var greeting: String = "Hello"
24+
/// ```swift
25+
/// @main
26+
/// struct Greet: ParsableCommand {
27+
/// @Argument var name: String
28+
/// @Argument var greeting: String = "Hello"
2829
///
29-
/// mutating func run() {
30-
/// print("\(greeting) \(name)!")
31-
/// }
30+
/// mutating func run() {
31+
/// print("\(greeting) \(name)!")
3232
/// }
33+
/// }
34+
/// ```
3335
///
3436
/// You can call this program with just a name or with a name and a
3537
/// greeting. When you supply both arguments, the first argument is always
@@ -49,8 +51,8 @@ public struct Argument<Value>:
4951
self._parsedValue = _parsedValue
5052
}
5153

52-
public init(from decoder: Decoder) throws {
53-
try self.init(_decoder: decoder)
54+
public init(from _decoder: Decoder) throws {
55+
try self.init(_decoder: _decoder)
5456
}
5557

5658
/// This initializer works around a quirk of property wrappers, where the

Sources/ArgumentParser/Parsable Properties/Flag.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@
1818
/// For example, the following program declares a flag that lets a user indicate
1919
/// that seconds should be included when printing the time.
2020
///
21-
/// @main
22-
/// struct Time: ParsableCommand {
23-
/// @Flag var includeSeconds = false
21+
/// ```swift
22+
/// @main
23+
/// struct Time: ParsableCommand {
24+
/// @Flag var includeSeconds = false
2425
///
25-
/// mutating func run() {
26-
/// if includeSeconds {
27-
/// print(Date.now.formatted(.dateTime.hour().minute().second()))
28-
/// } else {
29-
/// print(Date.now.formatted(.dateTime.hour().minute()))
30-
/// }
26+
/// mutating func run() {
27+
/// if includeSeconds {
28+
/// print(Date.now.formatted(.dateTime.hour().minute().second()))
29+
/// } else {
30+
/// print(Date.now.formatted(.dateTime.hour().minute()))
3131
/// }
3232
/// }
33+
/// }
34+
/// ```
3335
///
3436
/// `includeSeconds` has a default value of `false`, but becomes `true` if
3537
/// `--include-seconds` is provided on the command line.
@@ -74,8 +76,8 @@ public struct Flag<Value>: Decodable, ParsedWrapper {
7476
self._parsedValue = _parsedValue
7577
}
7678

77-
public init(from decoder: Decoder) throws {
78-
try self.init(_decoder: decoder)
79+
public init(from _decoder: Decoder) throws {
80+
try self.init(_decoder: _decoder)
7981
}
8082

8183
/// This initializer works around a quirk of property wrappers, where the

Sources/ArgumentParser/Parsable Properties/Option.swift

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@
2222
///
2323
/// For example, the following program defines three options:
2424
///
25-
/// @main
26-
/// struct Greet: ParsableCommand {
27-
/// @Option var greeting = "Hello"
28-
/// @Option var age: Int? = nil
29-
/// @Option var name: String
25+
/// ```swift
26+
/// @main
27+
/// struct Greet: ParsableCommand {
28+
/// @Option var greeting = "Hello"
29+
/// @Option var age: Int? = nil
30+
/// @Option var name: String
3031
///
31-
/// mutating func run() {
32-
/// print("\(greeting) \(name)!")
33-
/// if let age = age {
34-
/// print("Congrats on making it to the ripe old age of \(age)!")
35-
/// }
32+
/// mutating func run() {
33+
/// print("\(greeting) \(name)!")
34+
/// if let age = age {
35+
/// print("Congrats on making it to the ripe old age of \(age)!")
3636
/// }
3737
/// }
38+
/// }
39+
/// ```
3840
///
3941
/// `greeting` has a default value of `"Hello"`, which can be overridden by
4042
/// providing a different string as an argument, while `age` defaults to `nil`.
@@ -54,8 +56,8 @@ public struct Option<Value>: Decodable, ParsedWrapper {
5456
self._parsedValue = _parsedValue
5557
}
5658

57-
public init(from decoder: Decoder) throws {
58-
try self.init(_decoder: decoder)
59+
public init(from _decoder: Decoder) throws {
60+
try self.init(_decoder: _decoder)
5961
}
6062

6163
/// This initializer works around a quirk of property wrappers, where the
@@ -278,14 +280,14 @@ extension Option where Value: ExpressibleByArgument {
278280
Swap the order of the 'help' and 'completion' arguments.
279281
""")
280282
public init(
281-
wrappedValue: Value,
283+
wrappedValue _wrappedValue: Value,
282284
name: NameSpecification = .long,
283285
parsing parsingStrategy: SingleValueParsingStrategy = .next,
284286
completion: CompletionKind?,
285287
help: ArgumentHelp?
286288
) {
287289
self.init(
288-
wrappedValue: wrappedValue,
290+
wrappedValue: _wrappedValue,
289291
name: name,
290292
parsing: parsingStrategy,
291293
help: help,
@@ -441,7 +443,7 @@ extension Option {
441443
""")
442444
@_disfavoredOverload
443445
public init<T>(
444-
wrappedValue: Optional<T>,
446+
wrappedValue _wrappedValue: Optional<T>,
445447
name: NameSpecification = .long,
446448
parsing parsingStrategy: SingleValueParsingStrategy = .next,
447449
help: ArgumentHelp? = nil,
@@ -454,7 +456,7 @@ extension Option {
454456
kind: .name(key: key, specification: name),
455457
help: help,
456458
parsingStrategy: parsingStrategy.base,
457-
initial: wrappedValue,
459+
initial: _wrappedValue,
458460
completion: completion)
459461

460462
return ArgumentSet(arg)
@@ -544,7 +546,7 @@ extension Option {
544546
@_disfavoredOverload
545547
@preconcurrency
546548
public init<T>(
547-
wrappedValue: Optional<T>,
549+
wrappedValue _wrappedValue: Optional<T>,
548550
name: NameSpecification = .long,
549551
parsing parsingStrategy: SingleValueParsingStrategy = .next,
550552
help: ArgumentHelp? = nil,
@@ -559,7 +561,7 @@ extension Option {
559561
help: help,
560562
parsingStrategy: parsingStrategy.base,
561563
transform: transform,
562-
initial: wrappedValue,
564+
initial: _wrappedValue,
563565
completion: completion)
564566

565567
return ArgumentSet(arg)

Sources/ArgumentParser/Parsable Properties/OptionGroup.swift

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@
1414
/// Use an option group to include a group of options, flags, or arguments
1515
/// declared in a parsable type.
1616
///
17-
/// struct GlobalOptions: ParsableArguments {
18-
/// @Flag(name: .shortAndLong)
19-
/// var verbose: Bool
17+
/// ```swift
18+
/// struct GlobalOptions: ParsableArguments {
19+
/// @Flag(name: .shortAndLong)
20+
/// var verbose: Bool
2021
///
21-
/// @Argument var values: [Int]
22-
/// }
22+
/// @Argument var values: [Int]
23+
/// }
2324
///
24-
/// struct Options: ParsableArguments {
25-
/// @Option var name: String
26-
/// @OptionGroup var globals: GlobalOptions
27-
/// }
25+
/// struct Options: ParsableArguments {
26+
/// @Option var name: String
27+
/// @OptionGroup var globals: GlobalOptions
28+
/// }
29+
/// ```
2830
///
2931
/// The flag and positional arguments declared as part of `GlobalOptions` are
3032
/// included when parsing `Options`.
@@ -45,14 +47,14 @@ public struct OptionGroup<Value: ParsableArguments>: Decodable, ParsedWrapper {
4547
self._visibility = .default
4648
}
4749

48-
public init(from decoder: Decoder) throws {
49-
if let d = decoder as? SingleValueDecoder,
50+
public init(from _decoder: Decoder) throws {
51+
if let d = _decoder as? SingleValueDecoder,
5052
let value = try? d.previousValue(Value.self)
5153
{
5254
self.init(_parsedValue: .value(value))
5355
} else {
54-
try self.init(_decoder: decoder)
55-
if let d = decoder as? SingleValueDecoder {
56+
try self.init(_decoder: _decoder)
57+
if let d = _decoder as? SingleValueDecoder {
5658
d.saveValue(wrappedValue)
5759
}
5860
}

0 commit comments

Comments
 (0)