mirror of
				https://github.com/GayPizzaSpecifications/darwin-apk.git
				synced 2025-11-04 07:59:38 +00:00 
			
		
		
		
	Rescue graph building test into subcommand
This commit is contained in:
		
							
								
								
									
										32
									
								
								Sources/dpk-cli/Subcommands/DpkGraphCommand.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								Sources/dpk-cli/Subcommands/DpkGraphCommand.swift
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
			
		||||
/*
 | 
			
		||||
 * darwin-apk © 2024 Gay Pizza Specifications
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import Foundation
 | 
			
		||||
import ArgumentParser
 | 
			
		||||
import darwin_apk
 | 
			
		||||
 | 
			
		||||
struct DpkGraphCommand: AsyncParsableCommand {
 | 
			
		||||
  static let configuration = CommandConfiguration(commandName: "graph")
 | 
			
		||||
 | 
			
		||||
  func run() async throws(ExitCode) {
 | 
			
		||||
    let graph: ApkPackageGraph
 | 
			
		||||
    do {
 | 
			
		||||
      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)
 | 
			
		||||
    } catch {
 | 
			
		||||
      fatalError(error.localizedDescription)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if var out = TextFileWriter(URL(filePath: "shallowIsolates.txt")) {
 | 
			
		||||
      for node in graph.shallowIsolates { print(node, to: &out) }
 | 
			
		||||
    }
 | 
			
		||||
    if var out = TextFileWriter(URL(filePath: "deepIsolates.txt")) {
 | 
			
		||||
      for node in graph.deepIsolates { print(node, to: &out) }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user