Skip to content

Commit 4abae9a

Browse files
authored
Organize and elaborate on flag/option description in convert command help text (#700)
* Reorganize the flags and options for the docc convert command. * Customize the usage text and discussion for the docc preview command * Hide the index command from the top-level docc commands * Fix source breaking changes * Clarify and document documentation coverage flags and optios Also, it's no longer necessary to pass both '--experimental-documentation-coverage' and '--coverage-summary-level' to enable the default level coverage output. * Reorder diagnostic and fallback options in help text * Remove redundant "docc" prefix for catalog path argument * Move port option above convert options in preview help text
1 parent e2ac2bf commit 4abae9a

File tree

10 files changed

+640
-310
lines changed

10 files changed

+640
-310
lines changed

Sources/SwiftDocCUtilities/ArgumentParsing/ActionExtensions/ConvertAction+CommandInitialization.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension ConvertAction {
4747
let bundleDiscoveryOptions = BundleDiscoveryOptions(
4848
fallbackDisplayName: convert.fallbackBundleDisplayName,
4949
fallbackIdentifier: convert.fallbackBundleIdentifier,
50-
fallbackVersion: convert.fallbackBundleVersion,
50+
fallbackVersion: nil,
5151
fallbackDefaultCodeListingLanguage: convert.defaultCodeListingLanguage,
5252
fallbackDefaultModuleKind: convert.fallbackDefaultModuleKind,
5353
additionalSymbolGraphFiles: additionalSymbolGraphFiles
@@ -57,9 +57,9 @@ extension ConvertAction {
5757
// when running `docc preview` and `docc convert` without any of the fallback options.
5858
let documentationBundleURL: URL?
5959
if bundleDiscoveryOptions.infoPlistFallbacks.isEmpty {
60-
documentationBundleURL = convert.documentationBundle.urlOrFallback
60+
documentationBundleURL = convert.documentationCatalog.urlOrFallback
6161
} else {
62-
documentationBundleURL = convert.documentationBundle.url
62+
documentationBundleURL = convert.documentationCatalog.url
6363
}
6464

6565
// Initialize the ``ConvertAction`` with the options provided by the ``Convert`` command.
@@ -71,7 +71,7 @@ extension ConvertAction {
7171
htmlTemplateDirectory: convert.templateOption.templateURL ?? fallbackTemplateURL,
7272
emitDigest: convert.emitDigest,
7373
currentPlatforms: parsedPlatforms,
74-
buildIndex: convert.emitLMDBIndex || convert.index,
74+
buildIndex: convert.emitLMDBIndex,
7575
temporaryDirectory: FileManager.default.temporaryDirectory,
7676
documentationCoverageOptions: DocumentationCoverageOptions(
7777
from: convert.experimentalDocumentationCoverageOptions

Sources/SwiftDocCUtilities/ArgumentParsing/ArgumentValidation/URLArgumentValidator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ enum URLArgumentValidator {
4646
///
4747
/// - Throws: A `ValidationError` that includes the `argumentDescription` and current path.
4848
static func validateFileExists(_ url: URL?, forArgumentDescription argumentDescription: String) throws {
49-
// Validation is only necesary if a non-optional value has been passed.
49+
// Validation is only necessary if a non-optional value has been passed.
5050
guard let url = url else { return }
5151

5252
guard FileManager.default.fileExists(atPath: url.path) else {
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -11,22 +11,20 @@
1111
import ArgumentParser
1212
import Foundation
1313

14-
/// Resolves and validates a URL value that provides the path to a documentation bundle.
14+
/// Resolves and validates a URL value that provides the path to a documentation catalog.
1515
///
1616
/// This option is used by the ``Docc/Convert`` subcommand.
17-
public struct DocumentationBundleOption: DirectoryPathOption {
18-
17+
public struct DocumentationCatalogOption: DirectoryPathOption {
1918
public init() {}
2019

21-
/// The name of the command line argument used to specify a source bundle path.
22-
static let argumentValueName = "source-bundle-path"
23-
24-
/// The path to a bundle to be compiled by DocC.
20+
/// The path to a '.docc' documentation catalog directory of markup files and assets.
2521
@Argument(
2622
help: ArgumentHelp(
27-
"Path to a documentation bundle directory.",
28-
discussion: "The '.docc' bundle docc will build.",
29-
valueName: argumentValueName),
23+
"Path to a '.docc' documentation catalog directory.",
24+
valueName: "catalog-path"),
3025
transform: URL.init(fileURLWithPath:))
3126
public var url: URL?
3227
}
28+
29+
@available(*, deprecated, renamed: "DocumentationCatalogOption")
30+
public typealias DocumentationBundleOption = DocumentationCatalogOption
Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -16,51 +16,89 @@ import SwiftDocC
1616
///
1717
/// These options are used by the ``Docc/Convert`` subcommand.
1818
public struct DocumentationCoverageOptionsArgument: ParsableArguments {
19+
public init() {}
1920

20-
static var noCoverage: DocumentationCoverageOptionsArgument {
21-
var value = DocumentationCoverageOptionsArgument()
22-
value.level = .none
23-
return value
24-
}
25-
26-
public init() { }
21+
fileprivate static let noCoverage = DocumentationCoverageOptionsArgument()
2722

28-
@Flag(help: """
29-
Generates documentation coverage output. (currently Experimental)
30-
""")
23+
// The way the '--experimental-documentation-coverage' flag and the '--coverage-summary-level' option work together
24+
// doesn't match the possible values for `DocumentationCoverageLevel`.
25+
26+
@Flag(
27+
help: ArgumentHelp("Generate documentation coverage output.", discussion: """
28+
Detailed documentation coverage information will be written to 'documentation-coverage.json' in the output directory.
29+
""")
30+
)
3131
var experimentalDocumentationCoverage: Bool = false
3232

33-
/// The desired level of documentation coverage. Options are `none`, `brief`, and `detailed`. The default is `none`
33+
/// The desired level of documentation coverage. Options are `none`, `brief`, and `detailed`. The default is `.brief`
3434
@Option(
35-
name: .long, // TODO: `.customLong("level", withSingleDash: true)` doesn't work with `swift run docc …`
36-
parsing: .next,
37-
help: ArgumentHelp(
38-
"Desired level of documentation coverage output."))
35+
name: .customLong("coverage-summary-level"),
36+
help: ArgumentHelp("The level of documentation coverage information to write on standard out.", discussion: """
37+
The '--coverage-summary-level' level has no impact on the information in the 'documentation-coverage.json' file.
38+
The supported coverage summary levels are 'brief' and 'detailed'.
39+
""",
40+
valueName: "symbol-kind")
41+
)
42+
var summaryLevel: DocumentationCoverageLevel = .brief
43+
44+
@Option(help: .hidden)
45+
@available(*, deprecated, renamed: "summaryLevel")
3946
public var level: DocumentationCoverageLevel = .none
4047

48+
var effectiveSummaryLevel: DocumentationCoverageLevel {
49+
guard experimentalDocumentationCoverage else {
50+
return .none
51+
}
52+
switch summaryLevel {
53+
case .detailed:
54+
return .detailed
55+
case .none, .brief:
56+
return .brief
57+
}
58+
}
59+
4160
@Option(
42-
name: .long,
61+
name: .customLong("coverage-symbol-kind-filter"),
4362
parsing: ArrayParsingStrategy.upToNextOption,
44-
help: ArgumentHelp(
45-
"The kinds of entities to filter generated documentation for.",
46-
valueName: "kind"))
63+
help: ArgumentHelp("Filter documentation coverage to only analyze symbols of the specified symbol kinds.", discussion: """
64+
Specify a list of symbol kind values to filter the documentation coverage to only those types symbols.
65+
The supported symbol kind values are: \
66+
\(DocumentationCoverageOptions.KindFilterOptions.BitFlagRepresentation.allValueStrings.sorted().joined(separator: ", "))
67+
""",
68+
valueName: "symbol-kind")
69+
)
70+
public var symbolKindFilter: [DocumentationCoverageOptions.KindFilterOptions.BitFlagRepresentation] = []
71+
72+
@Option(parsing: ArrayParsingStrategy.upToNextOption, help: .hidden)
73+
@available(*, deprecated, renamed: "symbolKindFilter")
4774
public var kinds: [DocumentationCoverageOptions.KindFilterOptions.BitFlagRepresentation] = []
48-
75+
76+
@available(*, deprecated) // This deprecation silences the access of the deprecated `level` and `kind` options.
77+
public mutating func validate() throws {
78+
Docc.Convert.warnAboutDeprecatedOptionIfNeeded("level", message: "Use '--coverage-summary-level' instead.")
79+
Docc.Convert.warnAboutDeprecatedOptionIfNeeded("kinds", message: "Use '--coverage-symbol-kind-filter' instead.")
80+
81+
if !ProcessInfo.processInfo.arguments.contains("--coverage-summary-level"), level != .none {
82+
summaryLevel = level
83+
}
84+
symbolKindFilter.append(contentsOf: kinds)
85+
}
4986
}
5087

5188
// SwiftDocCUtilities imports SwiftDocC. SwiftDocC does not link against ArgumentParser (because it isn't about CLI). We conform here because this is the first place that we can. We implement in DocC.
5289
extension DocumentationCoverageLevel: ExpressibleByArgument {}
5390
extension DocumentationCoverageOptions.KindFilterOptions.BitFlagRepresentation: ExpressibleByArgument {}
5491

5592
extension DocumentationCoverageOptions {
56-
public init(from argumentInstance: DocumentationCoverageOptionsArgument) {
57-
58-
if argumentInstance.experimentalDocumentationCoverage {
59-
self = DocumentationCoverageOptions(
60-
level: argumentInstance.level,
61-
kindFilterOptions: DocumentationCoverageOptions.KindFilterOptions(bitFlags: argumentInstance.kinds))
62-
} else {
93+
public init(from arguments: DocumentationCoverageOptionsArgument) {
94+
guard arguments.experimentalDocumentationCoverage else {
6395
self = .noCoverage
96+
return
6497
}
98+
99+
self = DocumentationCoverageOptions(
100+
level: arguments.effectiveSummaryLevel,
101+
kindFilterOptions: .init(bitFlags: arguments.symbolKindFilter)
102+
)
65103
}
66104
}

Sources/SwiftDocCUtilities/ArgumentParsing/Options/PreviewOptions.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,8 @@ import Foundation
1515
///
1616
/// These options are used by the ``Docc/Preview`` subcommand.
1717
public struct PreviewOptions: ParsableArguments {
18-
1918
public init() { }
2019

21-
/// Converts a documentation bundle.
22-
///
23-
/// ``PreviewAction`` makes use of ``ConvertAction`` so we import all the options
24-
/// that ``Docc/Convert`` provides.
25-
@OptionGroup()
26-
public var convertCommand: Docc.Convert
27-
2820
/// The port number to use for the preview web server.
2921
///
3022
/// Defaults to `8080`.
@@ -34,6 +26,13 @@ public struct PreviewOptions: ParsableArguments {
3426
"Port number to use for the preview web server.",
3527
valueName: "port-number"))
3628
public var port: Int = 8080
29+
30+
/// Converts a documentation bundle.
31+
///
32+
/// ``PreviewAction`` makes use of ``ConvertAction`` so we import all the options
33+
/// that ``Docc/Convert`` provides.
34+
@OptionGroup()
35+
public var convertCommand: Docc.Convert
3736

3837
public mutating func validate() throws {
3938
// Check that a valid port has been provided

0 commit comments

Comments
 (0)