|
| 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 | +} |
0 commit comments