1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
|
/*
This source file is part of the Swift.org open source project
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
import ArgumentParser
import SwiftDocC
import Foundation
extension Docc {
/// Converts documentation markup, assets, and symbol information into a documentation archive.
public struct Convert: ParsableCommand {
public init() {}
/// The name of the directory docc will write its build artifacts to.
private static let buildDirectory = ".docc-build"
/// The file handle that should be used for emitting warnings during argument validation.
///
/// Provided as a static variable to allow for redirecting output in unit tests.
static var _errorLogHandle: LogHandle = .standardError
static var _diagnosticFormattingOptions: DiagnosticFormattingOptions = []
public static var configuration = CommandConfiguration(
abstract: "Convert documentation markup, assets, and symbol information into a documentation archive.",
usage: """
docc convert [<catalog-path>] [--additional-symbol-graph-dir <symbol-graph-dir>]
docc convert [<catalog-path>] [--additional-symbol-graph-dir <symbol-graph-dir>] [--output-dir <output-dir>]
docc convert [<catalog-path>] [--additional-symbol-graph-dir <symbol-graph-dir>] [--output-dir <output-dir>] [<availability-options>] [<diagnostic-options>] [<source-repository-options>] [<hosting-options>] [<info-plist-fallbacks>] [<feature-flags>] [<other-options>]
""",
discussion: """
When building documentation for source code, the 'convert' command is commonly invoked by other tools as part of a build workflow. Such build workflows can perform tasks to extract symbol graph information and may infer values for 'docc' flags and options from other build configuration.
When building documentation for a catalog that only contain articles or tutorial content, interacting with the 'docc convert' command directly can be a good alternative to using DocC via a build workflow.
"""
)
// Note:
// The order of the option groups in this file is reflected in the 'docc convert --help' output.
//
// The flags and options in this file is defined as internal with public accessors. This allows us to reorganize flags and options
// in the `docc` command line interface without source breaking changes.
// MARK: - Inputs & outputs
@OptionGroup(title: "Inputs & outputs")
var inputsAndOutputs: InputAndOutputOptions
struct InputAndOutputOptions: ParsableArguments {
@OptionGroup()
var documentationCatalog: DocumentationCatalogOption
@Option(
name: [.customLong("additional-symbol-graph-dir")],
help: "A path to a directory of additional symbol graph files.",
transform: URL.init(fileURLWithPath:)
)
var additionalSymbolGraphDirectory: URL?
@Option(
name: [.customLong("additional-symbol-graph-files")],
parsing: ArrayParsingStrategy.upToNextOption,
help: .hidden,
transform: URL.init(fileURLWithPath:)
)
@available(*, deprecated, renamed: "additionalSymbolGraphDirectory", message: "Use 'additionalSymbolGraphDirectory' instead. This deprecated API will be removed after 5.12 is released")
var additionalSymbolGraphFiles: [URL] = [] // Remove when other tools no longer use it. (rdar://72449411)
@Option(
name: [.customLong("output-path"), .customLong("output-dir"), .customShort("o")], // Remove "output-dir" when other tools no longer pass that option. (rdar://72449411)
help: "The location where the documentation compiler writes the built documentation.",
transform: URL.init(fileURLWithPath:)
)
var providedOutputURL: URL?
func validate() throws {
warnAboutDeprecatedOptionIfNeeded("additional-symbol-graph-files", message: "Use '--additional-symbol-graph-dir' instead.")
if let outputParent = providedOutputURL?.deletingLastPathComponent() {
// Verify that the intermediate directories exist for the output location.
var isDirectory: ObjCBool = false
guard FileManager.default.fileExists(atPath: outputParent.path, isDirectory: &isDirectory), isDirectory.boolValue else {
throw ValidationError("No directory exists at '\(outputParent.path)'.")
}
}
}
}
/// The user-provided path to a `.docc` documentation catalog.
public var documentationCatalog: DocumentationCatalogOption {
get { inputsAndOutputs.documentationCatalog }
set { inputsAndOutputs.documentationCatalog = newValue }
}
@available(*, deprecated, renamed: "documentationCatalog", message: "Use 'documentationCatalog' instead. This deprecated API will be removed after 5.12 is released")
public var documentationBundle: DocumentationBundleOption {
get { inputsAndOutputs.documentationCatalog }
set { inputsAndOutputs.documentationCatalog = newValue }
}
/// A user-provided path to a directory of additional symbol graph files that the convert action will process.
public var additionalSymbolGraphDirectory: URL? {
get { inputsAndOutputs.additionalSymbolGraphDirectory }
set { inputsAndOutputs.additionalSymbolGraphDirectory = newValue }
}
@available(*, deprecated, renamed: "additionalSymbolGraphDirectory", message: "Use 'additionalSymbolGraphDirectory' instead. This deprecated API will be removed after 5.12 is released")
public var additionalSymbolGraphFiles: [URL] { // Remove when other tools no longer use it. (rdar://72449411)
get { inputsAndOutputs.additionalSymbolGraphFiles }
set { inputsAndOutputs.additionalSymbolGraphFiles = newValue }
}
/// A user-provided location where the convert action writes the built documentation.
public var providedOutputURL: URL? {
get { inputsAndOutputs.providedOutputURL }
set { inputsAndOutputs.providedOutputURL = newValue }
}
/// The path to the directory that all build output should be placed in.
public var outputURL: URL {
// If an output location was passed as an argument, use it as-is.
if let providedOutputURL {
return providedOutputURL
}
var outputURL = documentationCatalog.urlOrFallback
// Check that the output is written in a build directory sub-folder
if outputURL.lastPathComponent != Convert.buildDirectory {
outputURL.appendPathComponent(Convert.buildDirectory)
}
return outputURL
}
// MARK: - Availability options
@OptionGroup(title: "Availability options")
var availabilityOptions: AvailabilityOptions
struct AvailabilityOptions: ParsableArguments {
@Option(
name: .customLong("platform"),
parsing: ArrayParsingStrategy.singleValue,
help: ArgumentHelp("Specify information about the current release of a platform.", discussion: """
Each platform's information is specified via separate "--platform" values using the following format: "name={platform name},version={semantic version}".
Optionally, the platform information can include a 'beta={true|false}' component. If no beta information is provided, the platform is considered not in beta.
""")
)
var platforms: [String] = []
}
/// User-provided platform name/version pairs.
///
/// Used to set the current release version of a platform. Contains an array of strings in the following format:
/// ```
/// name={platform name},version={semantic version}
/// ```
///
/// Optionally, the platform name/version pair can include a `beta={true|false}` component. If no beta information is provided the platform is considered not in beta.
///
/// # Example
/// ```
/// "name=macOS,version=10.1.2"
/// "name=macOS,version=10.1.2,beta=true"
/// ```
public var platforms: [String] {
get { availabilityOptions.platforms }
set { availabilityOptions.platforms = newValue }
}
/// The user-provided path to an executable that can be used to resolve links.
///
/// This is an optional value and an internal link resolver is used by default.
@OptionGroup() // This is only configured via environmental variables, so it doesn't display in the help text.
public var outOfProcessLinkResolverOption: OutOfProcessLinkResolverOption
// MARK: - Source repository options
/// Arguments for specifying information about the source code repository that hosts the documented project's code.
@OptionGroup(title: "Source repository options")
public var sourceRepositoryArguments: SourceRepositoryArguments
// MARK: - Hosting options
@OptionGroup(title: "Hosting options")
var hostingOptions: HostingOptions
struct HostingOptions: ParsableArguments {
@Option(
name: [.customLong("hosting-base-path")],
help: ArgumentHelp("The base path your documentation website will be hosted at.", discussion: """
For example, if you deploy your site to 'example.com/my_name/my_project/documentation' instead of 'example.com/documentation', pass '/my_name/my_project' as the base path.
""")
)
var hostingBasePath: String?
@Flag(
inversion: .prefixedNo,
exclusivity: .exclusive,
help: "Produce a DocC archive that supports static hosting environments."
)
var transformForStaticHosting = true
}
/// A Boolean value that is true if the DocC archive produced by this conversion will support static hosting environments.
///
/// This value defaults to true but can be explicitly disabled with the `--no-transform-for-static-hosting` flag.
public var transformForStaticHosting: Bool {
get { hostingOptions.transformForStaticHosting }
set { hostingOptions.transformForStaticHosting = newValue }
}
/// A user-provided relative path to be used in the archived output
var hostingBasePath: String? {
hostingOptions.hostingBasePath
}
/// The user-provided path to an HTML documentation template.
@OptionGroup()
public var templateOption: TemplateOption
// MARK: Diagnostic options
@OptionGroup(title: "Diagnostic options")
var diagnosticOptions: DiagnosticOptions
struct DiagnosticOptions: ParsableArguments {
@Flag(help: "Include 'note'/'information' level diagnostics in addition to warnings and errors.")
var analyze = false
@Option(
name: [.customLong("diagnostics-file"), .customLong("diagnostics-output-path")],
help: ArgumentHelp(
"The location where the documentation compiler writes the diagnostics file.",
discussion: "Specifying a diagnostic file path implies '--ide-console-output'."
),
transform: URL.init(fileURLWithPath:)
)
var diagnosticsOutputPath: URL?
@Option(
name: [.customLong("diagnostic-filter"), .long],
help: ArgumentHelp("Filter diagnostics with a lower severity than this level.", discussion:
"""
This option is ignored if `--analyze` is passed.
This filter level is inclusive. If a level of 'note' is specified, diagnostics with a severity up to and including 'note' will be printed.
\(supportedDiagnosticLevelsMessage)
""")
)
var diagnosticLevel: String?
@Flag(
name: [.customLong("ide-console-output"), .customLong("emit-fixits")],
help: "Format output to the console intended for an IDE or other tool to parse.")
var formatConsoleOutputForTools = false
@Flag(help: "Treat warnings as errors")
var warningsAsErrors = false
func validate() throws {
if analyze && diagnosticLevel != nil {
warnAboutDiagnostic(.init(
severity: .information,
identifier: "org.swift.docc.IgnoredDiagnosticsFilter",
summary: "'--diagnostic-filter' is ignored when '--analyze' is set."
))
}
if let level = diagnosticLevel, DiagnosticSeverity(level) == nil {
warnAboutDiagnostic(.init(
severity: .information,
identifier: "org.swift.docc.UnknownDiagnosticLevel",
summary: """
"\(level)" is not a valid diagnostic severity.
\(Self.supportedDiagnosticLevelsMessage)
"""
))
}
}
private static let supportedDiagnosticLevelsMessage = """
The supported diagnostic filter levels are:
- error
- warning
- note, info, information
- hint, notice
"""
}
/// Treat warning as errors.
public var warningsAsErrors: Bool {
get { diagnosticOptions.warningsAsErrors }
set { diagnosticOptions.warningsAsErrors = newValue }
}
/// A user-provided value that is true if output to the console should be formatted for an IDE or other tool to parse.
public var formatConsoleOutputForTools: Bool {
get { diagnosticOptions.formatConsoleOutputForTools }
set { diagnosticOptions.formatConsoleOutputForTools = newValue }
}
@available(*, deprecated, renamed: "formatConsoleOutputForTools", message: "Use 'formatConsoleOutputForTools' instead. This deprecated API will be removed after 5.10 is released")
public var emitFixits: Bool {
formatConsoleOutputForTools
}
/// A user-provided location where the convert action writes the diagnostics file.
public var diagnosticsOutputPath: URL? {
get { diagnosticOptions.diagnosticsOutputPath }
set { diagnosticOptions.diagnosticsOutputPath = newValue }
}
/// The diagnostic severity level to filter
public var diagnosticLevel: String? {
get { diagnosticOptions.diagnosticLevel }
set { diagnosticOptions.diagnosticLevel = newValue }
}
/// A user-provided value that is true if additional analyzer style warnings should be outputted to the terminal.
///
/// Defaults to false.
public var analyze: Bool {
get { diagnosticOptions.analyze }
set { diagnosticOptions.analyze = newValue }
}
// MARK: - Info.plist fallback options
@OptionGroup(title: "Info.plist fallbacks")
var infoPlistFallbacks: InfoPlistFallbackOptions
struct InfoPlistFallbackOptions: ParsableArguments {
@Option(
name: [.customLong("default-code-listing-language")],
help: "A fallback default language for code listings if no value is provided in the documentation catalogs's Info.plist file."
)
var defaultCodeListingLanguage: String?
@Option(
name: [.customLong("fallback-display-name"), .customLong("display-name")], // Remove spelling without "fallback" prefix when other tools no longer use it. (rdar://72449411)
help: ArgumentHelp("A fallback display name if no value is provided in the documentation catalogs's Info.plist file.", discussion: """
If no display name is provided in the catalogs's Info.plist file or via the '--fallback-display-name' option, \
DocC will infer a display name from the documentation catalog base name or from the module name from the symbol graph files provided \
via the '--additional-symbol-graph-dir' option.
""")
)
var fallbackBundleDisplayName: String?
@Option(
name: [.customLong("fallback-bundle-identifier"), .customLong("bundle-identifier")], // Remove spelling without "fallback" prefix when other tools no longer use it. (rdar://72449411)
help: ArgumentHelp("A fallback bundle identifier if no value is provided in the documentation catalogs's Info.plist file.", discussion: """
If no bundle identifier is provided in the catalogs's Info.plist file or via the '--fallback-bundle-identifier' option, \
DocC will infer a bundle identifier from the display name.
""")
)
var fallbackBundleIdentifier: String?
@Option(
name: [.customLong("fallback-bundle-version"), .customLong("bundle-version")], // Remove spelling without "fallback" prefix when other tools no longer use it. (rdar://72449411)
help: .hidden
)
@available(*, deprecated, message: "The bundle version isn't used for anything. This deprecated API will be removed after 5.12 is released")
var fallbackBundleVersion: String?
@Option(
help: ArgumentHelp("A fallback default module kind if no value is provided in the documentation catalogs's Info.plist file.", discussion: """
If no module kind is provided in the catalogs's Info.plist file or via the '--fallback-default-module-kind' option, \
DocC will display the module kind as a "Framework".
""")
)
var fallbackDefaultModuleKind: String?
func validate() throws {
for deprecatedOptionName in ["display-name", "bundle-identifier", "bundle-version"] {
warnAboutDeprecatedOptionIfNeeded(deprecatedOptionName, message: "Use '--fallback-\(deprecatedOptionName)' instead.")
}
}
}
/// A user-provided fallback display name for the documentation bundle.
///
/// If the documentation catalogs's Info.plist file contains a bundle display name, the documentation catalog ignores this fallback name.
public var fallbackBundleDisplayName: String? {
get { infoPlistFallbacks.fallbackBundleDisplayName }
set { infoPlistFallbacks.fallbackBundleDisplayName = newValue }
}
/// A user-provided fallback identifier for the documentation bundle.
///
/// If the documentation catalogs's Info.plist file contains a bundle identifier, the documentation catalog ignores this fallback identifier.
public var fallbackBundleIdentifier: String? {
get { infoPlistFallbacks.fallbackBundleIdentifier }
set { infoPlistFallbacks.fallbackBundleIdentifier = newValue }
}
/// A user-provided fallback version for the documentation bundle.
///
/// If the documentation catalogs's Info.plist file contains a bundle version, the documentation catalog ignores this fallback version.
@available(*, deprecated, message: "The bundle version isn't used for anything. This deprecated API will be removed after 5.12 is released")
public var fallbackBundleVersion: String? {
get { infoPlistFallbacks.fallbackBundleVersion }
set { infoPlistFallbacks.fallbackBundleVersion = newValue }
}
/// A user-provided default language for code listings.
///
/// If the documentation catalogs's Info.plist file contains a default code listing language, the documentation catalog ignores this fallback language.
public var defaultCodeListingLanguage: String? {
get { infoPlistFallbacks.defaultCodeListingLanguage }
set { infoPlistFallbacks.defaultCodeListingLanguage = newValue }
}
/// A user-provided default kind description for the module.
///
/// If the documentation catalogs's Info.plist file contains a default module kind, the documentation catalog ignores this fallback module kind.
public var fallbackDefaultModuleKind: String? {
get { infoPlistFallbacks.fallbackDefaultModuleKind }
set { infoPlistFallbacks.fallbackDefaultModuleKind = newValue }
}
// MARK: - Documentation coverage options
/// A user-provided value that is true if the user wants to opt in to Experimental documentation coverage generation.
///
/// Defaults to none.
@OptionGroup(title: "Documentation coverage (Experimental)")
public var experimentalDocumentationCoverageOptions: DocumentationCoverageOptionsArgument
// MARK: - Link resolution options
@OptionGroup(title: "Link resolution options (Experimental)")
var linkResolutionOptions: LinkResolutionOptions
struct LinkResolutionOptions: ParsableArguments {
@Option(
name: [.customLong("dependency")],
parsing: ArrayParsingStrategy.singleValue,
help: ArgumentHelp("A path to a documentation archive to resolve external links against.", discussion: """
Only documentation archives built with '--enable-experimental-external-link-support' are supported as dependencies.
"""),
transform: URL.init(fileURLWithPath:)
)
var dependencies: [URL] = []
mutating func validate() throws {
let fileManager = FileManager.default
var filteredDependencies: [URL] = []
for dependency in dependencies {
// Check that the dependency URL is a directory. We don't validate the extension.
var isDirectory: ObjCBool = false
guard fileManager.fileExists(atPath: dependency.path, isDirectory: &isDirectory) else {
Convert.warnAboutDiagnostic(.init(
severity: .warning,
identifier: "org.swift.docc.Dependency.NotFound",
summary: "No documentation archive exist at '\(dependency.path)'."
))
continue
}
guard isDirectory.boolValue else {
Convert.warnAboutDiagnostic(.init(
severity: .warning,
identifier: "org.swift.docc.Dependency.IsNotDirectory",
summary: "Dependency at '\(dependency.path)' is not a directory."
))
continue
}
// Check that the dependency contains both the expected files
let linkableEntitiesFile = dependency.appendingPathComponent(ConvertFileWritingConsumer.linkableEntitiesFileName, isDirectory: false)
let hasLinkableEntitiesFile = fileManager.fileExists(atPath: linkableEntitiesFile.path)
if !hasLinkableEntitiesFile {
Convert.warnAboutDiagnostic(.init(
severity: .warning,
identifier: "org.swift.docc.Dependency.MissingLinkableEntities",
summary: "Dependency at '\(dependency.path)' doesn't contain a is not a '\(linkableEntitiesFile.lastPathComponent)' file."
))
}
let linkableHierarchyFile = dependency.appendingPathComponent(ConvertFileWritingConsumer.linkHierarchyFileName, isDirectory: false)
let hasLinkableHierarchyFile = fileManager.fileExists(atPath: linkableHierarchyFile.path)
if !hasLinkableHierarchyFile {
Convert.warnAboutDiagnostic(.init(
severity: .warning,
identifier: "org.swift.docc.Dependency.MissingLinkHierarchy",
summary: "Dependency at '\(dependency.path)' doesn't contain a is not a '\(linkableHierarchyFile.lastPathComponent)' file."
))
}
if hasLinkableEntitiesFile && hasLinkableHierarchyFile {
filteredDependencies.append(dependency)
}
}
self.dependencies = filteredDependencies
}
}
/// A list of URLs to documentation archives that the local documentation depends on.
public var dependencies: [URL] {
get { linkResolutionOptions.dependencies }
set { linkResolutionOptions.dependencies = newValue }
}
// MARK: - Feature flag options
@OptionGroup(title: "Feature flags")
var featureFlags: FeatureFlagOptions
struct FeatureFlagOptions: ParsableArguments {
@Flag(help: "Allows for custom templates, like `header.html`.")
var experimentalEnableCustomTemplates = false
@Flag(help: .hidden)
var enableExperimentalDeviceFrameSupport = false
@Flag(help: "Inherit documentation for inherited symbols")
var enableInheritedDocs = false
@Flag(help: .hidden)
@available(*, deprecated, message: "Doxygen support is now enabled by default. This deprecated API will be removed after 5.10 is released")
var experimentalParseDoxygenCommands = false
@Flag(help: "Experimental: allow catalog directories without the `.docc` extension.")
var allowArbitraryCatalogDirectories = false
@Flag(
name: .customLong("enable-experimental-external-link-support"),
help: ArgumentHelp("Support external links to this documentation output.", discussion: """
Write additional link metadata files to the output directory to support resolving documentation links to the documentation in that output directory.
""")
)
var enableExperimentalLinkHierarchySerialization = false
@Flag(help: .hidden)
var experimentalModifyCatalogWithGeneratedCuration = false
@Flag(
name: .customLong("enable-experimental-overloaded-symbol-presentation"),
help: ArgumentHelp("Collects all the symbols that are overloads of each other onto a new merged-symbol page.")
)
var enableExperimentalOverloadedSymbolPresentation = false
@Flag(
name: .customLong("enable-experimental-mentioned-in"),
help: ArgumentHelp("Render a section on symbol documentation which links to articles that mention that symbol", discussion: """
Validates and filters symbols' parameter and return value documentation based on the symbol's function signature in each language representation.
""")
)
var enableExperimentalMentionedIn = false
@Flag(
name: .customLong("parameters-and-returns-validation"),
inversion: .prefixedEnableDisable,
help: ArgumentHelp("Validate parameter and return value documentation", discussion: """
Validates and filters symbols' parameter and return value documentation based on the symbol's function signature in each language representation.
""")
)
var enableParametersAndReturnsValidation = true
// This flag only exist to allow developers to pass the previous '--enable-experimental-...' flag without errors.
@Flag(name: .customLong("enable-experimental-parameters-and-returns-validation"), help: .hidden)
@available(*, deprecated, message: "This deprecated API will be removed after 6.0 is released")
var enableExperimentalParametersAndReturnsValidation = false
@Flag(help: "Write additional metadata files to the output directory.")
var emitDigest = false
@Flag(
help: ArgumentHelp(
"Writes an LMDB representation of the navigator index to the output directory.",
discussion: "A JSON representation of the navigator index is emitted by default."
)
)
var emitLMDBIndex = false
@Flag(help: .hidden)
@available(*, deprecated, renamed: "emitLMDBIndex", message: "Use 'emitLMDBIndex' instead. This deprecated API will be removed after 5.12 is released")
var index = false
@available(*, deprecated) // This deprecation silences the access of the deprecated `index` flag.
mutating func validate() throws {
Convert.warnAboutDeprecatedOptionIfNeeded("enable-experimental-objective-c-support", message: "This flag has no effect. Objective-C support is enabled by default.")
Convert.warnAboutDeprecatedOptionIfNeeded("enable-experimental-json-index", message: "This flag has no effect. The JSON render is emitted by default.")
Convert.warnAboutDeprecatedOptionIfNeeded("experimental-parse-doxygen-commands", message: "This flag has no effect. Doxygen support is enabled by default.")
Convert.warnAboutDeprecatedOptionIfNeeded("enable-experimental-parameters-and-returns-validation", message: "This flag has no effect. Parameter and return value validation is enabled by default.")
Convert.warnAboutDeprecatedOptionIfNeeded("index", message: "Use '--emit-lmdb-index' indead.")
emitLMDBIndex = emitLMDBIndex || index
}
}
/// A user-provided value that is true if the user wants to provide a custom template for rendered output.
///
/// Defaults to false
public var experimentalEnableCustomTemplates: Bool {
get { featureFlags.experimentalEnableCustomTemplates }
set { featureFlags.experimentalEnableCustomTemplates = newValue }
}
/// A user-provided value that is true if the user enables experimental support for device frames.
///
/// Defaults to false.
public var enableExperimentalDeviceFrameSupport: Bool {
get { featureFlags.enableExperimentalDeviceFrameSupport }
set { featureFlags.enableExperimentalDeviceFrameSupport = newValue }
}
/// A user-provided value that is true if experimental documentation inheritance is to be enabled.
///
/// Defaults to false.
public var enableInheritedDocs: Bool {
get { featureFlags.enableInheritedDocs }
set { featureFlags.enableInheritedDocs = newValue }
}
/// A user-provided value that is true if experimental Doxygen support should be enabled.
///
/// > Important: This flag is deprecated now that the feature is enabled by default, and will be removed in a future release.
@available(*, deprecated, message: "Doxygen support is now enabled by default. This deprecated API will be removed after 5.10 is released")
public var experimentalParseDoxygenCommands: Bool {
get { featureFlags.experimentalParseDoxygenCommands }
set { featureFlags.experimentalParseDoxygenCommands = newValue }
}
/// A user-provided value that is true if additional metadata files should be produced.
///
/// Defaults to false.
public var allowArbitraryCatalogDirectories: Bool {
get { featureFlags.allowArbitraryCatalogDirectories }
set { featureFlags.allowArbitraryCatalogDirectories = newValue }
}
/// A user-provided value that is true if the user enables experimental serialization of the local link resolution information.
public var enableExperimentalLinkHierarchySerialization: Bool {
get { featureFlags.enableExperimentalLinkHierarchySerialization }
set { featureFlags.enableExperimentalLinkHierarchySerialization = newValue }
}
/// A user-provided value that is true if the user wants to in-place modify the provided documentation catalog to write generated curation to documentation extension files.
///
/// Defaults to false
///
/// > Important: This will write new and updated files to the provided documentation catalog directory.
public var experimentalModifyCatalogWithGeneratedCuration: Bool {
get { featureFlags.experimentalModifyCatalogWithGeneratedCuration }
set { featureFlags.experimentalModifyCatalogWithGeneratedCuration = newValue }
}
/// A user-provided value that is true if the user enables experimental serialization of the local link resolution information.
public var enableExperimentalOverloadedSymbolPresentation: Bool {
get { featureFlags.enableExperimentalOverloadedSymbolPresentation }
set { featureFlags.enableExperimentalOverloadedSymbolPresentation = newValue }
}
/// A user-provided value that is true if the user enables experimental automatically generated "mentioned in"
/// links on symbols.
public var enableExperimentalMentionedIn: Bool {
get { featureFlags.enableExperimentalMentionedIn }
set { featureFlags.enableExperimentalMentionedIn = newValue }
}
/// A user-provided value that is true if the user enables experimental validation for parameters and return value documentation.
public var enableParametersAndReturnsValidation: Bool {
get { featureFlags.enableParametersAndReturnsValidation }
set { featureFlags.enableParametersAndReturnsValidation = newValue }
}
@available(*, deprecated, renamed: "enableParametersAndReturnsValidation", message: "Use 'enableParametersAndReturnsValidation' instead. This deprecated API will be removed after 6.0 is released")
public var enableExperimentalParametersAndReturnsValidation: Bool {
get { enableParametersAndReturnsValidation }
set { enableParametersAndReturnsValidation = newValue }
}
/// A user-provided value that is true if additional metadata files should be produced.
///
/// Defaults to false.
public var emitDigest: Bool {
get { featureFlags.emitDigest }
set { featureFlags.emitDigest = newValue }
}
/// A user-provided value that is true if the LMDB representation of the navigator index should be produced.
///
/// Defaults to false.
public var emitLMDBIndex: Bool {
get { featureFlags.emitLMDBIndex }
set { featureFlags.emitLMDBIndex = newValue }
}
/// This value is provided for backwards compatibility with existing clients but will be removed soon. Renamed to '--emit-lmdb-index'.
@available(*, deprecated, renamed: "emitLMDBIndex", message: "Use 'emitLMDBIndex' instead. This deprecated API will be removed after 5.12 is released")
public var index: Bool {
get { featureFlags.emitLMDBIndex }
set { featureFlags.emitLMDBIndex = newValue }
}
// MARK: - ParsableCommand conformance
public mutating func validate() throws {
if transformForStaticHosting {
if let templateURL = templateOption.templateURL {
let neededFileName: String
if hostingBasePath != nil {
neededFileName = HTMLTemplate.templateFileName.rawValue
}else {
neededFileName = HTMLTemplate.indexFileName.rawValue
}
let indexTemplate = templateURL.appendingPathComponent(neededFileName, isDirectory: false)
if !FileManager.default.fileExists(atPath: indexTemplate.path) {
throw TemplateOption.invalidHTMLTemplateError(
path: templateURL.path,
expectedFile: neededFileName
)
}
} else {
let invalidOrMissingTemplateDiagnostic = Diagnostic(
severity: .warning,
identifier: "org.swift.docc.MissingHTMLTemplate",
summary: "Invalid or missing HTML template directory",
explanation: """
Invalid or missing HTML template directory, relative to the docc \
executable, at: '\(templateOption.defaultTemplateURL.path)'.
Set the '\(TemplateOption.environmentVariableKey)' environment variable \
to use a custom HTML template.
Conversion will continue, but the produced DocC archive will not be \
compatible with static hosting environments.
Pass the '--no-transform-for-static-hosting' flag to silence this warning.
"""
)
print(
DiagnosticConsoleWriter.formattedDescription(for: invalidOrMissingTemplateDiagnostic),
to: &Self._errorLogHandle
)
transformForStaticHosting = false
}
}
}
public mutating func run() throws {
// Initialize a `ConvertAction` from the current options in the `Convert` command.
var convertAction = try ConvertAction(fromConvertCommand: self)
// Perform the conversion and print any warnings or errors found
try convertAction.performAndHandleResult()
}
// MARK: Warnings
static func warnAboutDeprecatedOptionIfNeeded(_ deprecatedOption: String, message: String) {
guard ProcessInfo.processInfo.arguments.contains("--\(deprecatedOption)") else {
return // Only warn if the flag is used
}
warnAboutDiagnostic(.init(
severity: .warning,
identifier: "org.swift.docc.DeprecatedOption",
summary: "'--\(deprecatedOption)' is deprecated. \(message)"
))
}
private static func warnAboutDiagnostic(_ diagnostic: Diagnostic) {
print(
DiagnosticConsoleWriter.formattedDescription(for: diagnostic, options: _diagnosticFormattingOptions),
to: &_errorLogHandle
)
}
}
}
|