Skip to content

Commit f14201a

Browse files
committed
Move definitions of documented option/flag names into DocumentedFlag
1 parent 4feaf9d commit f14201a

File tree

3 files changed

+30
-53
lines changed

3 files changed

+30
-53
lines changed

Sources/SwiftDocCPluginUtilities/CommandLineArguments/ParsedPluginArguments.swift

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,12 @@ struct ParsedPluginArguments {
1717

1818
/// Creates a new plugin arguments container by extracting the known plugin values from a command line argument list.
1919
init(extractingFrom arguments: inout CommandLineArguments) {
20-
enableCombinedDocumentation = arguments.extractFlag(named: Self.enableCombinedDocumentation).last ?? false
21-
disableLMDBIndex = arguments.extractFlag(named: Self.disableLMDBIndex).last ?? false
22-
verbose = arguments.extractFlag(named: Self.verbose).last ?? false
23-
help = arguments.extractFlag(named: Self.help).last ?? false
20+
enableCombinedDocumentation = arguments.extractFlag(.enableCombinedDocumentation) ?? false
21+
disableLMDBIndex = arguments.extractFlag(.disableLMDBIndex) ?? false
22+
verbose = arguments.extractFlag(.verbose) ?? false
23+
help = arguments.extractFlag(named: Self.help).last ?? false
2424
}
2525

26-
/// A plugin feature flag to enable building combined documentation for multiple targets.
27-
static let enableCombinedDocumentation = CommandLineArgument.Names(
28-
preferred: "--enable-experimental-combined-documentation"
29-
)
30-
31-
/// A plugin feature flag to skip adding the `--emit-lmdb-index` flag, that the plugin adds by default.
32-
static let disableLMDBIndex = CommandLineArgument.Names(
33-
preferred: "--disable-indexing", alternatives: ["--no-indexing"]
34-
)
35-
36-
/// A plugin feature flag to enable verbose logging.
37-
static let verbose = CommandLineArgument.Names(
38-
preferred: "--verbose"
39-
)
40-
4126
/// A common command line tool flag to print the help text instead of running the command.
4227
static let help = CommandLineArgument.Names(
4328
preferred: "--help", alternatives: ["-h"]
@@ -53,26 +38,18 @@ struct ParsedSymbolGraphArguments {
5338

5439
/// Creates a new symbol graph arguments container by extracting the known plugin values from a command line argument list.
5540
init(extractingFrom arguments: inout CommandLineArguments) {
56-
minimumAccessLevel = arguments.extractOption(named: Self.minimumAccessLevel).last
57-
skipSynthesizedSymbols = arguments.extractFlag(named: Self.skipSynthesizedSymbols).last
58-
includeExtendedTypes = arguments.extractFlag(named: Self.includeExtendedTypes, inverseNames: Self.excludeExtendedTypes).last
41+
minimumAccessLevel = arguments.extractOption(.minimumAccessLevel)
42+
skipSynthesizedSymbols = arguments.extractFlag(.skipSynthesizedSymbols)
43+
includeExtendedTypes = arguments.extractFlag(.extendedTypes)
44+
}
45+
}
46+
47+
private extension CommandLineArguments {
48+
mutating func extractFlag(_ flag: DocumentedFlag) -> Bool? {
49+
extractFlag(named: flag.names, inverseNames: flag.inverseNames).last
5950
}
6051

61-
/// The minimum access level that the symbol graph extractor will emit symbols for.
62-
static let minimumAccessLevel = CommandLineArgument.Names(
63-
preferred: "--symbol-graph-minimum-access-level"
64-
)
65-
66-
/// The feature flag to omit synthesized symbols when extracting symbol information.
67-
static let skipSynthesizedSymbols = CommandLineArgument.Names(
68-
preferred: "--experimental-skip-synthesized-symbols"
69-
)
70-
71-
/// A pair of positive and negative feature flags to either include or exclude extended types when extracting symbol information.
72-
static let includeExtendedTypes = CommandLineArgument.Names(
73-
preferred: "--include-extended-types"
74-
)
75-
static let excludeExtendedTypes = CommandLineArgument.Names(
76-
preferred: "--exclude-extended-types"
77-
)
52+
mutating func extractOption(_ flag: DocumentedFlag) -> String? {
53+
extractOption(named: flag.names).last
54+
}
7855
}

Sources/SwiftDocCPluginUtilities/DocumentedPluginFlags/DocumentedFlag.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ extension DocumentedFlag {
2828
/// A plugin feature flag to enable building combined documentation for multiple targets.
2929
///
3030
/// - Note: This flag requires that the `docc` executable supports ``Feature/linkDependencies``.
31-
static let enableCombinedDocumentationSupport = Self(
32-
names: ParsedPluginArguments.enableCombinedDocumentation,
31+
static let enableCombinedDocumentation = Self(
32+
names: .init(preferred: "--enable-experimental-combined-documentation"),
3333
abstract: "Create a combined DocC archive with all generated documentation.",
3434
discussion: """
3535
Experimental feature that allows targets to link to pages in their dependencies and that \
@@ -38,8 +38,8 @@ extension DocumentedFlag {
3838
)
3939

4040
/// A plugin feature flag to skip adding the `--emit-lmdb-index` flag, that the plugin adds by default.
41-
static let disableIndex = Self(
42-
names: ParsedPluginArguments.disableLMDBIndex,
41+
static let disableLMDBIndex = Self(
42+
names: .init(preferred: "--disable-indexing", alternatives: ["--no-indexing"]),
4343
abstract: "Disable indexing for the produced DocC archive.",
4444
discussion: """
4545
Produces a DocC archive that is best-suited for hosting online but incompatible with Xcode.
@@ -48,7 +48,7 @@ extension DocumentedFlag {
4848

4949
/// A plugin feature flag to enable verbose logging.
5050
static let verbose = Self(
51-
names: ParsedPluginArguments.verbose,
51+
names: .init(preferred: "--verbose"),
5252
abstract: "Increase verbosity to include informational output.",
5353
discussion: nil
5454
)
@@ -66,17 +66,17 @@ extension DocumentedFlag {
6666
/// - Note: This flag is only available starting from Swift 5.8. It should be hidden from the `--help` command for lower toolchain versions.
6767
/// However, we do not hide the flag entirely, because this enables us to give a more precise warning when accidentally used with Swift 5.7 or lower.
6868
static let extendedTypes = Self(
69-
names: ParsedSymbolGraphArguments.includeExtendedTypes,
70-
inverseNames: ParsedSymbolGraphArguments.excludeExtendedTypes,
71-
abstract: "Control whether extended types from other modules are shown in the produced DocC archive. (default: \(Self.defaultExtendedTypesValue))",
69+
names: .init(preferred: "--include-extended-types"),
70+
inverseNames: .init(preferred: "--exclude-extended-types"),
71+
abstract: "Control whether extended types from other modules are shown in the produced DocC archive. (default: --\(Self.defaultExtendedTypesValue ? "include" : "exclude")-extended-types)",
7272
discussion: "Allows documenting symbols that a target adds to its dependencies."
7373
)
7474

7575
/// Exclude synthesized symbols from the generated documentation.
7676
///
7777
/// `--experimental-skip-synthesized-symbols` produces a DocC archive without compiler-synthesized symbols.
7878
static let skipSynthesizedSymbols = Self(
79-
names: ParsedSymbolGraphArguments.skipSynthesizedSymbols,
79+
names: .init(preferred: "--experimental-skip-synthesized-symbols"),
8080
abstract: "Exclude synthesized symbols from the generated documentation.",
8181
discussion: """
8282
Experimental feature that produces a DocC archive without compiler synthesized symbols.
@@ -85,16 +85,16 @@ extension DocumentedFlag {
8585

8686
/// The minimum access level that the symbol graph extractor will emit symbols for
8787
static let minimumAccessLevel = Self(
88-
names: ParsedSymbolGraphArguments.minimumAccessLevel,
88+
names: .init(preferred: "--symbol-graph-minimum-access-level"),
8989
abstract: "Include symbols with this access level or more. (default: public)",
9090
discussion: """
9191
Supported access level values are: `open`, `public`, `internal`, `private`, `fileprivate`
9292
"""
9393
)
9494

9595
#if swift(>=5.9)
96-
private static let defaultExtendedTypesValue = ParsedSymbolGraphArguments.includeExtendedTypes.preferred
96+
private static let defaultExtendedTypesValue = true
9797
#else
98-
private static let defaultExtendedTypesValue = ParsedSymbolGraphArguments.excludeExtendedTypes.preferred
98+
private static let defaultExtendedTypesValue = false
9999
#endif
100100
}

Sources/SwiftDocCPluginUtilities/HelpInformation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public enum HelpInformation {
4444
}
4545

4646
var supportedPluginFlags = [
47-
DocumentedFlag.disableIndex,
47+
DocumentedFlag.disableLMDBIndex,
4848
DocumentedFlag.verbose,
4949
]
5050

5151
let doccFeatures = (try? DocCFeatures(doccExecutable: doccExecutableURL)) ?? .init()
5252
if doccFeatures.contains(.linkDependencies) {
53-
supportedPluginFlags.insert(DocumentedFlag.enableCombinedDocumentationSupport, at: 1)
53+
supportedPluginFlags.insert(DocumentedFlag.enableCombinedDocumentation, at: 1)
5454
}
5555

5656
for flag in supportedPluginFlags {

0 commit comments

Comments
 (0)