Skip to content

Commit 683dbdb

Browse files
authored
Merge pull request #350 from tayloraswift/simplify-cli
Simplify cli
2 parents c4415d6 + 1c6200f commit 683dbdb

12 files changed

+128
-81
lines changed

Guides/docs.docc/Getting started.md

+24-21
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,23 @@ You need to have [Docker](https://www.docker.com/) installed on your development
1111
It is theoretically possible to run Unidoc without Docker, but Docker makes it much easier to do so, because you will not need to (directly) manage a local [MongoDB](https://mongodb.com) deployment.
1212

1313

14-
## Setting up a local database
14+
## Installing Unidoc
15+
16+
The examples in this tutorial assume you are building Unidoc from source. However, you can also download [pre-built binaries](/Quickstart) for a select set of platforms.
17+
18+
19+
## Setting up a local database automatically
20+
21+
Unidoc can set up a `mongod` instance for you automatically through the `unidoc init` command. This tool takes a directory path as an argument, which it uses to persist the state of the database. In the example below, we will create the documentation database in a directory named `unidoc` in your home directory.
22+
23+
@Code(file: init-server.sh, title: init-server.sh)
24+
25+
26+
## Setting up a local database manually
27+
28+
> Note:
29+
> The steps in this section are provided for educational purposes, to help you understand how Unidoc works. If you have set up the database automatically, you can skip this section.
30+
1531

1632
A Unidoc server is a server that talks to a second server, a MongoDB server. Therefore, before you can start a Unidoc server, you need to set up and launch a local [MongoDB](https://github.com/tayloraswift/swift-mongodb) deployment.
1733

@@ -49,7 +65,7 @@ This file:
4965
The `unidoc-test` network is helpful for testing, but for the purposes of this tutorial, you will mostly be accessing the `mongod` process through `localhost:27017`.
5066

5167

52-
## Initializing the database
68+
### Initializing the database
5369

5470
The mongod instance will create a `.mongod` directory at the root of the cloned repository. This directory contains the state of the deployment, and like all database deployments, it can outlive the mongod process. This means you can kill (or crash) the mongod instance but it will not lose data unless you clear or delete its data directory.
5571

@@ -62,24 +78,13 @@ docker exec -t unidoc-mongod-container /bin/mongosh --file /unidoc-rs-init.js
6278
This only needs to be done **once** per deployment lifecycle. (For example, after clearing the `.mongod` data directory.)
6379

6480

65-
### Connecting to the database
81+
## Connecting to the database
6682

67-
Once you have a `unidoc-mongod-container` running in the background, you can start a documentation server. There are many ways to run a documentation server, but if you are developing in a Docker container, the easiest way is compile Unidoc and run the server as a normal process.
83+
Once you have a `unidoc-mongod-container` running in the background, you can start a documentation server by running `unidoc preview`.
6884

6985
@Code(file: start-server.sh, title: start-server.sh)
7086

7187

72-
### Generating certificates
73-
74-
#### Unidoc < 0.17.0
75-
76-
If you are starting the server for the first time, you likely need to populate the `Assets/certificates/` directory with TLS certificates. See <doc:GeneratingCertificates> for instructions on how to do this.
77-
78-
#### Unidoc ≥ 0.17.0
79-
80-
You do not need to generate certificates, as Unidoc 0.17.0 can run locally in insecure mode.
81-
82-
8388
## Populating a local documentation server
8489

8590
If you did all of the previous steps correctly, you should be able to navigate to [`localhost:8080/`](http://localhost:8080/) and view a blank homepage.
@@ -111,26 +116,24 @@ Uploading symbol graph...
111116
Successfully uploaded symbol graph!
112117
```
113118

114-
Because you built these docs “abnormally” (meaning: not from a GitHub repository), they won’t show up in the homepage, but you can view them by navigating directly to [`localhost:8080/docs/swift`](http://localhost:8080/docs/swift).
119+
You can view the docs by navigating to [`localhost:8080/docs/swift`](http://localhost:8080/docs/swift).
115120

116121
> Note:
117122
You may see a lot of compiler errors when building the standard library. This is expected, as the documentation for the standard library contains many errors.
118123

119124

120125
### Building documentation for a local project
121126

122-
Building documentation for a local project is similar to building documentation for the standard library, except you need to provide a path to a directory containing the project.
127+
Building documentation for a local project is similar to building documentation for the standard library, except you need to provide a path to the project directory.
123128

124-
Let’s try building documentation for [`swift-nio`](https://github.com/apple/swift-nio). First, we need to clone the repository.
129+
Let’s try building documentation for [`swift-nio`](https://github.com/apple/swift-nio). First, let’s clone the repository to a directory in `/swift`, which is a plausible place to store Git repositories in a devcontainer.
125130

126131
```bash
127132
cd /swift
128133
git clone https://github.com/apple/swift-nio
129134
```
130135

131-
**Where** you clone the repository is important, because you will need to tell Unidoc where to find the project. In this example, we cloned the repository inside a directory called `/swift`, which is a plausible place to store Git repositories in a devcontainer.
132-
133-
Next, you can try building `swift-nio` with `unidoc local`, specifying the path to the search directory (`/swift`) with the `-I` option.
136+
Next, you can try building `swift-nio` with `unidoc local`, specifying the path to the project (`/swift/swift-nio`) with the `-i` option.
134137

135138
@Code(file: load-swift-nio.sh, title: load-swift-nio.sh)
136139

Guides/docs.docc/Quickstart.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,24 @@ You should be able to view the symbol graph and its documentation at [`http://lo
9090

9191
## 5. Generating documentation for SwiftPM packages
9292

93-
Now, let’s generate documentation for [swift-collections](https://github.com/apple/swift-collections), a popular SwiftPM package. Download the library’s source code to a sibling directory.
93+
Now, let’s generate documentation for [swift-collections](https://github.com/apple/swift-collections), a popular SwiftPM package. Download the library’s source code using Git.
9494

9595
```bash
96-
cd ..
9796
git clone https://github.com/apple/swift-collections
98-
cd -
9997
```
10098

101-
Generating documentation for a package is similar to generating documentation for the standard library, except you need to specify a search path to a directory containing the project. Because you downloaded the `swift-collections` repository to a sibling directory, you can use `..` for the search path.
99+
To generate documentation for a package, you need to tell Unidoc where to find the project. Because you downloaded the `swift-collections` repository to a child directory, you can use `-i swift-collections` for the project path.
102100

103101
```bash
104-
unidoc local swift-collections -I ..
102+
unidoc local -i swift-collections
103+
```
104+
105+
The default value for the project path is the current working directory (`.`), so alternatively, you could navigate to the `swift-collections` directory and run `unidoc local` without any arguments.
106+
107+
```bash
108+
cd swift-collections
109+
unidoc local
110+
cd -
105111
```
106112

107113
You should be able to view the symbol graph and its documentation at [`http://localhost:8080/tags/swift-collections`](http://localhost:8080/tags/swift-collections).
@@ -110,13 +116,11 @@ You should be able to view the symbol graph and its documentation at [`http://lo
110116
> The `swift-collections` documentation.
111117
}
112118

113-
Finally, let’s generate documentation for a package that depends on `swift-collections`. Download the source code for [swift-async-algorithms](https://github.com/apple/swift-async-algorithms) to another sibling directory.
119+
Finally, let’s generate documentation for a package that depends on `swift-collections`. Download the source code for [swift-async-algorithms](https://github.com/apple/swift-async-algorithms) to a sibling directory of `swift-collections`.
114120

115121
```bash
116-
cd ..
117122
git clone https://github.com/apple/swift-async-algorithms
118-
cd -
119-
unidoc local swift-async-algorithms -I ..
123+
unidoc local -i swift-async-algorithms
120124
```
121125

122126

Guides/docs.docc/local/init-server.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
swift --version
2+
swift run -c release unidoc init ~/unidoc
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
swift run -c release unidoc local swift-nio -I /swift
1+
swift run -c release unidoc local -i /swift/swift-nio

Guides/docs.docc/local/unidoc-install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
UNIDOC_MIRROR=https://static.swiftinit.org/unidoc
2-
UNIDOC_VERSION=0.19.4
2+
UNIDOC_VERSION=0.19.6
33
UNIDOC_PLATFORM=macOS-ARM64
44

55
curl -L $UNIDOC_MIRROR/$UNIDOC_VERSION/$UNIDOC_PLATFORM/unidoc.tar.gz \

Package.resolved

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"originHash" : "9db681321dbead3e4e8b376a25cec9c94acb432f4b4e11fe4f453acf75469f2e",
2+
"originHash" : "2156eef098820d69df79f04f2b3255dd80304e9ecf437ad8150bd17b7448fcb6",
33
"pins" : [
44
{
55
"identity" : "indexstore-db",
@@ -15,8 +15,8 @@
1515
"kind" : "remoteSourceControl",
1616
"location" : "https://github.com/apple/swift-argument-parser",
1717
"state" : {
18-
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
19-
"version" : "1.5.0"
18+
"branch" : "main",
19+
"revision" : "83c5134a242086c053261095937f9964301a453a"
2020
}
2121
},
2222
{

Package.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ let package:Package = .init(
102102
.package(url: "https://github.com/tayloraswift/swift-png", .upToNextMinor(
103103
from: "4.4.3")),
104104

105-
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(
106-
from: "1.5.0")),
105+
// .package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(
106+
// from: "1.5.0")),
107+
.package(url: "https://github.com/apple/swift-argument-parser", branch: "main"),
107108
.package(url: "https://github.com/apple/swift-atomics", .upToNextMinor(
108109
from: "1.2.0")),
109110
.package(url: "https://github.com/apple/swift-collections", .upToNextMinor(

Sources/SymbolGraphBuilder/SSGC.Compile.swift

+45-19
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ extension SSGC
3131

3232
@Option(
3333
name: [.customLong("search-path"), .customShort("I")],
34-
help: "Where to look for a SwiftPM package to build, if building locally",
34+
help: """
35+
DEPRECATED: Where to look for a SwiftPM package to build, if building locally
36+
""",
3537
completion: .directory)
3638
var search:FilePath.Directory? = nil
3739

@@ -67,13 +69,19 @@ extension SSGC
6769
help: "Run in CI mode under the specified validation level")
6870
var ci:ValidationBehavior? = nil
6971

72+
@Option(
73+
name: [.customLong("project-path"), .customShort("p")],
74+
help: "Path to a local project to build",
75+
completion: .directory)
76+
var projectPath:FilePath.Directory?
77+
7078
@Option(
7179
name: [.customLong("package-name"), .customShort("n")],
7280
help: """
7381
The symbolic name of the project to build — \
7482
this is not the name specified in the `Package.swift` manifest!
7583
""")
76-
var project:String
84+
var project:String?
7785

7886
@Option(
7987
name: [.customLong("project-type"), .customShort("b")],
@@ -240,10 +248,11 @@ extension SSGC.Compile
240248

241249
let object:SymbolGraphObject<Void>
242250

243-
if let repo:String = self.repo,
251+
if let project:String = self.project,
252+
let repo:String = self.repo,
244253
let ref:String = self.ref
245254
{
246-
let symbol:Symbol.Package = .init(self.project)
255+
let symbol:Symbol.Package = .init(project)
247256

248257
defer
249258
{
@@ -277,10 +286,39 @@ extension SSGC.Compile
277286
logger: logger,
278287
clean: self.cleanArtifacts)
279288
}
280-
else if
281-
let search:FilePath.Directory = self.search
289+
else if case "swift"? = self.project
290+
{
291+
object = try workspace.build(some: SSGC.StandardLibraryBuild.swift,
292+
toolchain: toolchain,
293+
status: status,
294+
logger: logger,
295+
clean: self.cleanArtifacts)
296+
}
297+
else
282298
{
283-
let build:SSGC.PackageBuild = .local(project: search / self.project,
299+
let computedPath:FilePath.Directory
300+
301+
if let projectPath:FilePath.Directory = self.projectPath
302+
{
303+
computedPath = projectPath
304+
}
305+
else if
306+
let search:FilePath.Directory = self.search,
307+
let name:String = self.project
308+
{
309+
print("""
310+
Warning: '--search-path' is deprecated, use '--project-path' with the
311+
full path to the project root instead
312+
""")
313+
314+
computedPath = search / name
315+
}
316+
else
317+
{
318+
throw SSGC.ProjectPathRequiredError.init()
319+
}
320+
321+
let build:SSGC.PackageBuild = .local(project: computedPath,
284322
using: ".build.ssgc",
285323
as: self.type)
286324

@@ -298,18 +336,6 @@ extension SSGC.Compile
298336
logger: logger,
299337
clean: self.cleanArtifacts)
300338
}
301-
else if self.project == "swift"
302-
{
303-
object = try workspace.build(some: SSGC.StandardLibraryBuild.swift,
304-
toolchain: toolchain,
305-
status: status,
306-
logger: logger,
307-
clean: self.cleanArtifacts)
308-
}
309-
else
310-
{
311-
throw SSGC.SearchPathRequiredError.init()
312-
}
313339

314340
let output:FilePath = self.output ?? workspace.location / "docs.bson"
315341
try output.open(.writeOnly,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extension SSGC
2+
{
3+
struct ProjectPathRequiredError:Error
4+
{
5+
}
6+
}

Sources/SymbolGraphBuilder/SSGC.SearchPathRequiredError.swift

-6
This file was deleted.

Sources/UnidocClient/Unidoc.Client.swift

+19-15
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,13 @@ extension Unidoc.Client<HTTP.Client2>
279279
}
280280

281281
public
282-
func buildAndUpload(local name:String,
283-
search:FilePath.Directory?,
282+
func buildAndUpload(local:FilePath.Directory?,
283+
name:String?,
284284
type:SSGC.ProjectType,
285285
with toolchain:Unidoc.Toolchain) async throws
286286
{
287-
let object:SymbolGraphObject<Void> = try await self.build(local: name,
288-
search: search,
287+
let object:SymbolGraphObject<Void> = try await self.build(local: local,
288+
name: name,
289289
type: type,
290290
with: toolchain)
291291

@@ -301,13 +301,13 @@ extension Unidoc.Client<HTTP.Client2>
301301
extension Unidoc.Client<HTTP.Client1>
302302
{
303303
public
304-
func buildAndUpload(local name:String,
305-
search:FilePath.Directory?,
304+
func buildAndUpload(local:FilePath.Directory?,
305+
name:String?,
306306
type:SSGC.ProjectType,
307307
with toolchain:Unidoc.Toolchain) async throws
308308
{
309-
let object:SymbolGraphObject<Void> = try await self.build(local: name,
310-
search: search,
309+
let object:SymbolGraphObject<Void> = try await self.build(local: local,
310+
name: name,
311311
type: type,
312312
with: toolchain)
313313

@@ -318,13 +318,13 @@ extension Unidoc.Client<HTTP.Client1>
318318
http://\(self.http.remote):\(self.port)/tags/\(object.metadata.package.id)
319319
""")
320320
}
321-
}
321+
}
322322
extension Unidoc.Client
323323
{
324324
/// Name is case-sensitive, so it is not modeled as a ``Symbol.Package``.
325325
private
326-
func build(local name:String,
327-
search:FilePath.Directory?,
326+
func build(local:FilePath.Directory?,
327+
name:String?,
328328
type:SSGC.ProjectType,
329329
with toolchain:Unidoc.Toolchain) async throws -> SymbolGraphObject<Void>
330330
{
@@ -334,7 +334,6 @@ extension Unidoc.Client
334334
var arguments:[String] = [
335335
"compile",
336336

337-
"--package-name", "\(name)",
338337
"--project-type", "\(type)",
339338
"--workspace", "\(workspace.location)",
340339
"--output", "\(docs)",
@@ -354,10 +353,15 @@ extension Unidoc.Client
354353
arguments.append("--sdk")
355354
arguments.append("\(sdk)")
356355
}
357-
if let search:FilePath.Directory
356+
if let local:FilePath.Directory
357+
{
358+
arguments.append("--project-path")
359+
arguments.append("\(local)")
360+
}
361+
if let name:String
358362
{
359-
arguments.append("--search-path")
360-
arguments.append("\(search)")
363+
arguments.append("--package-name")
364+
arguments.append("\(name)")
361365
}
362366

363367
let ssgc:SystemProcess = try .init(command: self.executablePath, arguments: arguments)

0 commit comments

Comments
 (0)