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

Commit 5a68134

Browse files
authored
Merge branch 'master' into mattt/commonmark-output-improvements
2 parents 93b33c1 + 0b2291a commit 5a68134

File tree

8 files changed

+95
-10
lines changed

8 files changed

+95
-10
lines changed

Package.resolved

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

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ let package = Package(
1919
.package(url: "https://github.com/SwiftDocOrg/Markup.git", .upToNextMinor(from: "0.0.3")),
2020
.package(url: "https://github.com/NSHipster/SwiftSyntaxHighlighter.git", .revision("1.0.0")),
2121
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.0.2")),
22+
.package(url: "https://github.com/apple/swift-log.git", .upToNextMinor(from: "1.2.0")),
23+
.package(url: "https://github.com/NSHipster/swift-log-github-actions.git", .upToNextMinor(from: "0.0.1")),
2224
],
2325
targets: [
2426
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2527
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2628
.target(
2729
name: "swift-doc",
28-
dependencies: ["ArgumentParser", "SwiftDoc", "SwiftSemantics", "SwiftMarkup", "CommonMarkBuilder", "HypertextLiteral", "Markup", "DCOV", "GraphViz", "SwiftSyntaxHighlighter"]
30+
dependencies: ["ArgumentParser", "SwiftDoc", "SwiftSemantics", "SwiftMarkup", "CommonMarkBuilder", "HypertextLiteral", "Markup", "DCOV", "GraphViz", "SwiftSyntaxHighlighter", "Logging", "LoggingGitHubActions"]
2931
),
3032
.target(
3133
name: "DCOV",

README.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,43 @@ $ make install
4444

4545
### Usage
4646

47-
`swift-doc` takes one or more paths and enumerates them recursively,
47+
OVERVIEW: A utility for generating documentation for Swift code.
48+
49+
USAGE: swift-doc <subcommand>
50+
51+
OPTIONS:
52+
-h, --help Show help information.
53+
54+
SUBCOMMANDS:
55+
generate Generates Swift documentation
56+
coverage Generates documentation coverage statistics for Swift
57+
files
58+
diagram Generates diagram of Swift symbol relationships
59+
60+
#### swift-doc generate
61+
62+
OVERVIEW: Generates Swift documentation
63+
64+
USAGE: swift-doc generate [<inputs> ...] --module-name <module-name> [--output <output>] [--format <format>]
65+
66+
ARGUMENTS:
67+
<inputs> One or more paths to Swift files
68+
69+
OPTIONS:
70+
-n, --module-name <module-name>
71+
The name of the module
72+
-o, --output <output> The path for generated output (default:
73+
.build/documentation)
74+
-f, --format <format> The output format (default: commonmark)
75+
-h, --help Show help information.
76+
77+
The `generate` subcommand
78+
takes one or more paths and enumerates them recursively,
4879
collecting all Swift files into a single "module"
4980
and generating documentation accordingly.
5081

5182
```terminal
52-
$ swift doc generate path/to/SwiftProject/Sources
83+
$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject
5384
$ tree .build/documentation
5485
$ documentation/
5586
├── Home
@@ -64,21 +95,32 @@ in CommonMark / GitHub Wiki format,
6495
but you can change that with the `--output` and `--format` option flags.
6596

6697
```terminal
67-
$ swift doc generate path/to/SwiftProject/Sources --output Documentation --format html
98+
$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject --output Documentation --format html
6899
$ Documentation/
69100
├── (...)
70101
└── index.html
71102
```
72103

73104
#### swift-doc coverage
74105

106+
OVERVIEW: Generates documentation coverage statistics for Swift files
107+
108+
USAGE: swift-doc coverage [<inputs> ...] [--output <output>]
109+
110+
ARGUMENTS:
111+
<inputs> One or more paths to Swift files
112+
113+
OPTIONS:
114+
-o, --output <output> The path for generated report
115+
-h, --help Show help information.
116+
75117
The `coverage` subcommand
76118
generates documentation coverage statistics for Swift files.
77119

78120
```terminal
79121
$ git clone https://github.com/SwiftDocOrg/SwiftSemantics.git
80122
81-
$ swift run swift-doc coverage SwiftSemantics/Sources/ --output "dcov.json"
123+
$ swift run swift-doc coverage SwiftSemantics/Sources --output "dcov.json"
82124
$ cat dcov.json | jq ".data.totals"
83125
{
84126
"count": 207,
@@ -110,6 +152,16 @@ please reach out by [opening an Issue][open an issue]!
110152

111153
#### swift-doc diagram
112154

155+
OVERVIEW: Generates diagram of Swift symbol relationships
156+
157+
USAGE: swift-doc diagram [<inputs> ...]
158+
159+
ARGUMENTS:
160+
<inputs> One or more paths to Swift files
161+
162+
OPTIONS:
163+
-h, --help Show help information.
164+
113165
The `diagram` subcommand
114166
generates a graph of APIs in [DOT format][dot]
115167
that can be rendered by [GraphViz][graphviz] into a diagram.

Sources/swift-doc/Subcommands/Generate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ extension SwiftDoc {
105105
try $0.value.write(to: url, format: format)
106106
}
107107
}
108+
} catch {
109+
logger.error("\(error)")
108110
}
109111
}
110112
}

Sources/swift-doc/Supporting Types/Components/Relationships.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct Relationships: Component {
8686
do {
8787
svg = try HypertextLiteral.HTML(String(data: graph.render(using: algorithm, to: .svg), encoding: .utf8) ?? "")
8888
} catch {
89-
print(error)
89+
logger.error("\(error)")
9090
}
9191

9292
return #"""

Sources/swift-doc/Supporting Types/Pages/HomePage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct HomePage: Page {
3232
globalTypealiasNames.insert(`typealias`.name)
3333
case let `operator` as Operator:
3434
operatorNames.insert(`operator`.name)
35-
case let function as Function where !function.isOperator:
35+
case let function as Function where function.isOperator:
3636
operatorNames.insert(function.name)
3737
case let function as Function:
3838
globalFunctionNames.insert(function.name)

Sources/swift-doc/Supporting Types/Pages/SidebarPage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct SidebarPage: Page {
3030
globalTypealiasNames.insert(`typealias`.name)
3131
case let `operator` as Operator:
3232
operatorNames.insert(`operator`.name)
33-
case let function as Function where !function.isOperator:
33+
case let function as Function where function.isOperator:
3434
operatorNames.insert(function.name)
3535
case let function as Function:
3636
globalFunctionNames.insert(function.name)

Sources/swift-doc/main.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import ArgumentParser
22
import Foundation
3+
import Logging
4+
import LoggingGitHubActions
5+
6+
LoggingSystem.bootstrap { label in
7+
if ProcessInfo.processInfo.environment["GITHUB_ACTIONS"] == "true" {
8+
return GitHubActionsLogHandler.standardOutput(label: label)
9+
} else {
10+
return StreamLogHandler.standardOutput(label: label)
11+
}
12+
}
13+
14+
let logger = Logger(label: "org.swiftdoc.swift-doc")
315

416
let fileManager = FileManager.default
517
let fileAttributes: [FileAttributeKey : Any] = [.posixPermissions: 0o744]
@@ -10,8 +22,7 @@ var standardError = FileHandle.standardError
1022
struct SwiftDoc: ParsableCommand {
1123
static var configuration = CommandConfiguration(
1224
abstract: "A utility for generating documentation for Swift code.",
13-
subcommands: [Generate.self, Coverage.self, Diagram.self],
14-
defaultSubcommand: Generate.self
25+
subcommands: [Generate.self, Coverage.self, Diagram.self]
1526
)
1627
}
1728

0 commit comments

Comments
 (0)