Skip to content

Commit 6c47275

Browse files
committed
simplify Unidoc’s CLI by adding a direct --project-path argument that defaults to current working directory
1 parent c4415d6 commit 6c47275

File tree

7 files changed

+87
-49
lines changed

7 files changed

+87
-49
lines changed

Package.resolved

Lines changed: 3 additions & 3 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 & 2 deletions
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

Lines changed: 45 additions & 19 deletions
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,
Lines changed: 6 additions & 0 deletions
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

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

Sources/UnidocClient/Unidoc.Client.swift

Lines changed: 19 additions & 15 deletions
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)

Sources/unidoc-tools/Main.Local.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ extension Main
1010
struct Local
1111
{
1212
@Argument
13-
var project:String
13+
var project:String?
14+
15+
@Option(
16+
name: [.customLong("project-path"), .customShort("i")],
17+
help: "The path to the project to build",
18+
completion: .directory)
19+
var projectPath:FilePath.Directory = "."
20+
1421

1522
@Option(
1623
name: [.customLong("host"), .customShort("h")],
@@ -35,7 +42,7 @@ extension Main
3542

3643
@Option(
3744
name: [.customLong("input"), .customShort("I")],
38-
help: "The path to a directory containing the project to build",
45+
help: "DEPRECATED: The path to a directory containing the project to build",
3946
completion: .directory)
4047
var input:FilePath.Directory?
4148

@@ -78,8 +85,8 @@ extension Main.Local:AsyncParsableCommand
7885

7986
print("Connecting to \(self.host):\(self.port)...")
8087

81-
try await unidoc.buildAndUpload(local: self.project,
82-
search: self.input,
88+
try await unidoc.buildAndUpload(local: self.projectPath,
89+
name: self.project,
8390
type: self.book ? .book : .package,
8491
with: toolchain)
8592
}

0 commit comments

Comments
 (0)