mirror of
				https://github.com/GayPizzaSpecifications/darwin-apk.git
				synced 2025-11-04 07:59:38 +00:00 
			
		
		
		
	Read from repository configs instead of hardcoding repos/arch for update
This commit is contained in:
		@ -41,25 +41,7 @@ struct DpkSearchCommand: AsyncParsableCommand {
 | 
			
		||||
    let match: any PatternMatcher
 | 
			
		||||
    match = try matcher.init(patterns: patterns, ignoreCase: !self.caseSensitive)
 | 
			
		||||
 | 
			
		||||
    let repositories: [String], architectures: [String]
 | 
			
		||||
    do {
 | 
			
		||||
      repositories = try await PropertyFile.read(name: "repositories")
 | 
			
		||||
    } catch {
 | 
			
		||||
      print("Failed to read repositories: \(error.localizedDescription)")
 | 
			
		||||
      throw .failure
 | 
			
		||||
    }
 | 
			
		||||
    do {
 | 
			
		||||
      architectures = try await PropertyFile.read(name: "arch")
 | 
			
		||||
    } catch {
 | 
			
		||||
      print("Failed to read arch: \(error.localizedDescription)")
 | 
			
		||||
      throw .failure
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let localRepositories = repositories.flatMap { repo in
 | 
			
		||||
      architectures.map { arch in
 | 
			
		||||
        URL(filePath: ApkIndexRepository(name: repo, arch: arch).localName, directoryHint: .notDirectory)
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    let localRepositories = try await RepositoriesConfig().localRepositories
 | 
			
		||||
    let index: ApkIndex
 | 
			
		||||
    do {
 | 
			
		||||
      index = ApkIndex.merge(try localRepositories.map(ApkIndex.init))
 | 
			
		||||
@ -75,12 +57,3 @@ struct DpkSearchCommand: AsyncParsableCommand {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct PropertyFile {
 | 
			
		||||
  static func read(name: String) async throws -> [String] {
 | 
			
		||||
    try await URL(filePath: name, directoryHint: .notDirectory).lines
 | 
			
		||||
      .map { $0.trimmingCharacters(in: .whitespaces) }
 | 
			
		||||
      .filter { !$0.isEmpty && $0.first != "#" }  // Ignore empty & commented lines
 | 
			
		||||
      .reduce(into: [String]()) { $0.append($1) }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -7,15 +7,17 @@ import Foundation
 | 
			
		||||
import ArgumentParser
 | 
			
		||||
import darwin_apk
 | 
			
		||||
 | 
			
		||||
struct DpkUpdateCommand: ParsableCommand {
 | 
			
		||||
struct DpkUpdateCommand: AsyncParsableCommand {
 | 
			
		||||
  static let configuration = CommandConfiguration(
 | 
			
		||||
    commandName: "update",
 | 
			
		||||
    abstract: "Update the system package repositories.",
 | 
			
		||||
    aliases: [ "u" ])
 | 
			
		||||
 | 
			
		||||
  func run() throws {
 | 
			
		||||
  func run() async throws {
 | 
			
		||||
    print("Updating package repositories")
 | 
			
		||||
    let repositories = try await RepositoriesConfig().repositories
 | 
			
		||||
    var updater = ApkIndexUpdater()
 | 
			
		||||
    updater.repositories.append(contentsOf: repositories)
 | 
			
		||||
    updater.update()
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user