Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit e93bba0

Browse files
committed
Consolidate swift-api-diagram into swift-doc diagram subcommand
1 parent 3521862 commit e93bba0

File tree

5 files changed

+35
-42
lines changed

5 files changed

+35
-42
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ let package = Package(
2424
name: "DCOV",
2525
dependencies: []
2626
),
27-
.target(
28-
name: "swift-api-diagram",
29-
dependencies: ["SwiftDoc", "SwiftSemantics", "Commander"]
30-
),
3127
.target(
3228
name: "swift-api-inventory",
3329
dependencies: ["SwiftDoc", "SwiftSemantics", "Commander"]

Sources/swift-api-diagram/main.swift

Lines changed: 0 additions & 26 deletions
This file was deleted.

Sources/swift-api-diagram/GraphViz.swift renamed to Sources/swift-doc/Subcommands/Diagram.swift

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
import SwiftSemantics
1+
import ArgumentParser
2+
import Foundation
23
import SwiftDoc
4+
import SwiftSemantics
35

4-
fileprivate extension String {
5-
func indented(by spaces: Int = 2) -> String {
6-
return String(repeating: " ", count: spaces) + self
6+
extension SwiftDoc {
7+
struct Diagram: ParsableCommand {
8+
struct Options: ParsableArguments {
9+
@Argument(help: "One or more paths to Swift files")
10+
var inputs: [String]
11+
}
12+
13+
static var configuration = CommandConfiguration(abstract: "Generates diagram of Swift symbol relationships")
14+
15+
@OptionGroup()
16+
var options: Options
17+
18+
func run() throws {
19+
let module = try Module(paths: options.inputs)
20+
print(GraphViz.diagram(of: module), to: &standardOutput)
21+
}
722
}
823
}
924

@@ -19,7 +34,7 @@ enum GraphViz {
1934

2035
while !superclasses.isEmpty {
2136
let subclasses = Set(superclasses.flatMap { module.interface.typesInheriting(from: $0) }
22-
.filter { $0.isPublic })
37+
.filter { $0.isPublic })
2338
defer { superclasses = subclasses }
2439
classClusters[baseClass, default: []].formUnion(subclasses)
2540
}
@@ -43,8 +58,8 @@ enum GraphViz {
4358
if cluster.count > 1 {
4459
clusterLines = (
4560
["", "subgraph cluster_\(baseClass.id.description.replacingOccurrences(of: ".", with: "_")) {"] +
46-
clusterLines.map { $0.indented() } +
47-
["}", ""]
61+
clusterLines.map { $0.indented() } +
62+
["}", ""]
4863
)
4964
}
5065

@@ -60,9 +75,17 @@ enum GraphViz {
6075
}
6176

6277
lines = ["digraph \(module.name) {"] +
63-
lines.map { $0.indented() } +
64-
["}"]
78+
lines.map { $0.indented() } +
79+
["}"]
6580

6681
return lines.joined(separator: "\n")
6782
}
6883
}
84+
85+
// MARK: -
86+
87+
fileprivate extension String {
88+
func indented(by spaces: Int = 2) -> String {
89+
return String(repeating: " ", count: spaces) + self
90+
}
91+
}

Sources/swift-doc/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var standardError = FileHandle.standardError
1010
struct SwiftDoc: ParsableCommand {
1111
static var configuration = CommandConfiguration(
1212
abstract: "A utility for generating documentation for Swift code.",
13-
subcommands: [Generate.self, Coverage.self],
13+
subcommands: [Generate.self, Coverage.self, Diagram.self],
1414
defaultSubcommand: Generate.self
1515
)
1616
}

0 commit comments

Comments
 (0)