prefer to print to stderr for console chatter

This commit is contained in:
2024-11-17 02:59:13 +11:00
parent 20e76918fe
commit c239b8e424
9 changed files with 29 additions and 10 deletions

View File

@ -1,37 +0,0 @@
/*
* darwin-apk © 2024 Gay Pizza Specifications
* SPDX-License-Identifier: Apache-2.0
*/
import Foundation
import ArgumentParser
public struct ApkRepositoriesConfig {
public let repositories: [ApkIndexRepository]
public init() async throws(ExitCode) {
do {
self.repositories = try await Self.readConfig(name: "repositories").flatMap { repo in
Self.readConfig(name: "arch").map { arch in
ApkIndexRepository(name: repo, arch: arch)
}
}.reduce(into: []) { $0.append($1) }
} catch {
print("Failed to read repository configurations, \(error.localizedDescription)")
throw .failure
}
}
private static func readConfig(name: String)
-> AsyncFilterSequence<AsyncMapSequence<AsyncLineSequence<URL.AsyncBytes>, String>> {
return URL(filePath: name, directoryHint: .notDirectory).lines
.map { $0.trimmingCharacters(in: .whitespaces) }
.filter { !$0.isEmpty && $0.first != "#" } // Ignore empty & commented lines
}
}
public extension ApkIndex {
@inlinable static func resolve(_ config: ApkRepositoriesConfig, fetch: ApkIndexFetchMode) async throws -> Self {
try await Self.resolve(config.repositories, fetch: fetch)
}
}

View File

@ -45,6 +45,7 @@ public extension ApkIndex {
}
local = URL(filePath: repository.localName)
case .update:
//FIXME: Don't call print in the lib
print("Fetching \"\(repository.resolved)\"")
local = try await ApkIndexDownloader.fetch(repository: repository)
}