From 7236e8057040eb1a9e7abce2329d2bfd026a79aa Mon Sep 17 00:00:00 2001 From: Siddharth Gupta Date: Sat, 11 Jul 2020 13:43:04 +0800 Subject: [PATCH] Ability to exclude symbols from generated documentation --- README.md | 11 ++++++----- Sources/SwiftDoc/Module.swift | 12 ++++++++---- Sources/swift-doc/Subcommands/Generate.swift | 7 ++++++- action.yml | 4 ++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d86248fe..ce28f3e6 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ $ make install OVERVIEW: Generates Swift documentation - USAGE: swift doc generate [ ...] --module-name [--output ] [--format ] [--base-url ] + USAGE: swift doc generate [ ...] --module-name [--output ] [--format ] [--base-url ] [--excluded-symbols ] ARGUMENTS: One or more paths to Swift files @@ -77,11 +77,12 @@ $ make install OPTIONS: -n, --module-name The name of the module - -o, --output The path for generated output (default: - .build/documentation) + -o, --output The path for generated output (default: .build/documentation) -f, --format The output format (default: commonmark) - --base-url The base URL used for all relative URLs in generated - documents. (default: /) + --base-url The base URL used for all relative URLs in generated documents. (default: /) + --excluded-symbols + A file containing a line separated list of symbols to be excluded from the generated documentation + --version Show the version. -h, --help Show help information. The `generate` subcommand diff --git a/Sources/SwiftDoc/Module.swift b/Sources/SwiftDoc/Module.swift index 0b09eb8d..b5acec90 100644 --- a/Sources/SwiftDoc/Module.swift +++ b/Sources/SwiftDoc/Module.swift @@ -7,16 +7,16 @@ public final class Module { public let sourceFiles: [SourceFile] public let interface: Interface - public required init(name: String = "Anonymous", sourceFiles: [SourceFile]) { + public required init(name: String = "Anonymous", sourceFiles: [SourceFile], exclusions: [String] = []) { self.name = name self.sourceFiles = sourceFiles let imports = sourceFiles.flatMap { $0.imports } - let symbols = sourceFiles.flatMap { $0.symbols } + let symbols = sourceFiles.flatMap { $0.symbols }.filter({ !exclusions.contains($0.name) }) self.interface = Interface(imports: imports, symbols: symbols) } - public convenience init(name: String = "Anonymous", paths: [String]) throws { + public convenience init(name: String = "Anonymous", paths: [String], exclusionsFilePath: String? = nil) throws { var sources: [(file: URL, directory: URL)] = [] let fileManager = FileManager.default @@ -34,8 +34,12 @@ public final class Module { } } + var excludedSymbols = [String]() + if let exclusionsFilePath = exclusionsFilePath { + excludedSymbols = try String(contentsOfFile: exclusionsFilePath).components(separatedBy: "\n").filter { !$0.isEmpty } + } let sourceFiles = try sources.parallelMap { try SourceFile(file: $0.file, relativeTo: $0.directory) } - self.init(name: name, sourceFiles: sourceFiles) + self.init(name: name, sourceFiles: sourceFiles, exclusions: excludedSymbols) } } diff --git a/Sources/swift-doc/Subcommands/Generate.swift b/Sources/swift-doc/Subcommands/Generate.swift index 16bb70d3..ea3a5558 100644 --- a/Sources/swift-doc/Subcommands/Generate.swift +++ b/Sources/swift-doc/Subcommands/Generate.swift @@ -34,6 +34,11 @@ extension SwiftDoc { default: "/", help: "The base URL used for all relative URLs in generated documents.") var baseURL: String + + @Option(name: .customLong("excluded-symbols"), + default: nil, + help: "A file containing a line separated list of symbols to be excluded from the generated documentation") + var exclusionsFilePath: String? } static var configuration = CommandConfiguration(abstract: "Generates Swift documentation") @@ -42,7 +47,7 @@ extension SwiftDoc { var options: Options func run() throws { - let module = try Module(name: options.moduleName, paths: options.inputs) + let module = try Module(name: options.moduleName, paths: options.inputs, exclusionsFilePath: options.exclusionsFilePath) let baseURL = options.baseURL let outputDirectoryURL = URL(fileURLWithPath: options.output) diff --git a/action.yml b/action.yml index e49b486b..9d481a04 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,8 @@ inputs: description: "The path for generated output" required: true default: "./.build/documentation" + excluded-symbols: + description: "File containing a list of symbols to exclude from the generated documenttion" runs: using: "docker" @@ -30,6 +32,8 @@ runs: "${{ inputs.module-name }}", --output, "${{ inputs.output }}", + --excluded-symbols, + "${{ inputs.excluded-symbols }}", ] branding: