diff --git a/Sources/apk/Graph/ApkPackageGraph.swift b/Sources/apk/Graph/ApkPackageGraph.swift index c0ea6cf..cad2494 100644 --- a/Sources/apk/Graph/ApkPackageGraph.swift +++ b/Sources/apk/Graph/ApkPackageGraph.swift @@ -3,20 +3,20 @@ * SPDX-License-Identifier: Apache-2.0 */ -class ApkPackageGraph { - let pkgIndex: ApkIndex +public class ApkPackageGraph { + public let pkgIndex: ApkIndex private var _nodes = [ApkPackageGraphNode]() - var nodes: [ApkPackageGraphNode] { self._nodes } - var shallowIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.parents.isEmpty) } - var deepIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.children.isEmpty) } + public var nodes: [ApkPackageGraphNode] { self._nodes } + public var shallowIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.parents.isEmpty) } + public var deepIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.children.isEmpty) } - init(index: ApkIndex) { + public init(index: ApkIndex) { self.pkgIndex = index } - func buildGraphNode() { + public func buildGraphNode() { var provides = [String: Int]() for (idx, package) in self.pkgIndex.packages.enumerated() { diff --git a/Sources/apk/Graph/ApkPackageGraphNode.swift b/Sources/apk/Graph/ApkPackageGraphNode.swift index 034b0b0..6471d44 100644 --- a/Sources/apk/Graph/ApkPackageGraphNode.swift +++ b/Sources/apk/Graph/ApkPackageGraphNode.swift @@ -5,7 +5,7 @@ import Foundation -class ApkPackageGraphNode { +public class ApkPackageGraphNode { private weak var graph: ApkPackageGraph! let package: ApkIndexPackage @@ -21,7 +21,7 @@ class ApkPackageGraphNode { } extension ApkPackageGraphNode: CustomStringConvertible { - var description: String { + public var description: String { var result = "node[\(self.package.name)]" if !self.parents.isEmpty { result += ", parents[\(self.parents.lazy.map(\.description).joined(separator: ", "))]" diff --git a/Sources/dpk-cli/CommandLine.swift b/Sources/dpk-cli/CommandLine.swift index e4c42a7..ee9dfa6 100644 --- a/Sources/dpk-cli/CommandLine.swift +++ b/Sources/dpk-cli/CommandLine.swift @@ -16,6 +16,7 @@ struct DarwinApkCLI: AsyncParsableCommand { DpkUpdateCommand.self, DpkUpgradeCommand.self, DpkSearchCommand.self, - DpkInfoCommand.self + DpkInfoCommand.self, + DpkGraphCommand.self ]) } diff --git a/Sources/apk/Index/ApkIndexUpdate.swift b/Sources/dpk-cli/Subcommands/DpkGraphCommand.swift similarity index 69% rename from Sources/apk/Index/ApkIndexUpdate.swift rename to Sources/dpk-cli/Subcommands/DpkGraphCommand.swift index a48bf2a..561b0d9 100644 --- a/Sources/apk/Index/ApkIndexUpdate.swift +++ b/Sources/dpk-cli/Subcommands/DpkGraphCommand.swift @@ -4,18 +4,17 @@ */ import Foundation +import ArgumentParser +import darwin_apk -public struct ApkIndexUpdater { - public var repositories: [ApkIndexRepository] +struct DpkGraphCommand: AsyncParsableCommand { + static let configuration = CommandConfiguration(commandName: "graph") - public init() { - self.repositories = [] - } - - public func buildGraph() async { + func run() async throws(ExitCode) { let graph: ApkPackageGraph do { - graph = ApkPackageGraph(index: try await ApkIndexReader.resolve(self.repositories, fetch: .lazy)) + let localRepositories = try await ApkRepositoriesConfig() + graph = ApkPackageGraph(index: try await ApkIndexReader.resolve(localRepositories.repositories, fetch: .lazy)) graph.buildGraphNode() try graph.pkgIndex.description.write(to: URL(filePath: "packages.txt"), atomically: false, encoding: .utf8) diff --git a/Sources/apk/Utility/TextFileWriter.swift b/Sources/dpk-cli/TextFileWriter.swift similarity index 100% rename from Sources/apk/Utility/TextFileWriter.swift rename to Sources/dpk-cli/TextFileWriter.swift