Skip to content

Commit d323b05

Browse files
committed
Set up diff command line inputs.
1 parent e6b8152 commit d323b05

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import ArgumentParser
12+
import Foundation
13+
import SwiftDocC
14+
15+
extension Docc.ProcessArchive {
16+
struct Diff: ParsableCommand {
17+
18+
// MARK: - Configuration
19+
20+
static var configuration = CommandConfiguration(
21+
commandName: "diff",
22+
abstract: "Produce the symbol diff between two Render JSON files.",
23+
shouldDisplay: true)
24+
25+
// MARK: - Command Line Options & Arguments
26+
27+
@Argument(
28+
help: ArgumentHelp(
29+
"The path to a Render JSON file to be compared.",
30+
valueName: "renderJSON1"),
31+
transform: URL.init(fileURLWithPath:))
32+
var firstRenderJSON: URL
33+
34+
@Argument(
35+
help: ArgumentHelp(
36+
"The path to a second Render JSON file to be compared.",
37+
valueName: "renderJSON2"),
38+
transform: URL.init(fileURLWithPath:))
39+
var secondRenderJSON: URL
40+
41+
// MARK: - Execution
42+
43+
public mutating func run() throws {
44+
let firstRenderJSONData = try Data(contentsOf: firstRenderJSON)
45+
let secondRenderJSONData = try Data(contentsOf: secondRenderJSON)
46+
47+
let decoder = RenderJSONDecoder.makeDecoder()
48+
let firstRenderNode = try decoder.decode(RenderNode.self, from: firstRenderJSONData)
49+
let secondRenderNode = try decoder.decode(RenderNode.self, from: secondRenderJSONData)
50+
51+
let difference = firstRenderNode._difference(from: secondRenderNode)
52+
print(difference)
53+
}
54+
55+
}
56+
}

Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/ProcessArchive.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension Docc {
1818
static var configuration = CommandConfiguration(
1919
commandName: "process-archive",
2020
abstract: "Perform operations on documentation archives ('.doccarchive' directories).",
21-
subcommands: [TransformForStaticHosting.self, Index.self])
21+
subcommands: [TransformForStaticHosting.self, Index.self, Diff.self])
2222

2323
}
2424
}

0 commit comments

Comments
 (0)