[swcomp] Replace ContainerCommand.Entry with ContainerType

This commit is contained in:
Timofey Solomko committed 2021-09-19 15:15:55 +03:00
1 parent 19c788eb30
commit 15a99d1448
3 files changed
+7 -12

No files matched your search

+2 -3
View File
@@ -9,6 +9,8 @@ import SwiftCLI
class SevenZipCommand: ContainerCommand {
typealias ContainerType = SevenZipContainer
let name = "7z"
let shortDescription = "Extracts a 7-Zip container"
@@ -18,7 +20,4 @@ class SevenZipCommand: ContainerCommand {
let archive = Parameter()
let openFunction: (Data) throws -> [SevenZipEntry] = SevenZipContainer.open
let infoFunction: (Data) throws -> [SevenZipEntryInfo] = SevenZipContainer.info
}
@@ -9,7 +9,7 @@ import SwiftCLI
protocol ContainerCommand: Command {
associatedtype Entry: ContainerEntry
associatedtype ContainerType: Container
var info: Flag { get }
var extract: Key<String> { get }
@@ -17,9 +17,6 @@ protocol ContainerCommand: Command {
var archive: Parameter { get }
var openFunction: (Data) throws -> [Entry] { get }
var infoFunction: (Data) throws -> [Entry.Info] { get }
}
extension ContainerCommand {
@@ -33,7 +30,7 @@ extension ContainerCommand {
let fileData = try Data(contentsOf: URL(fileURLWithPath: self.archive.value),
options: .mappedIfSafe)
if info.value {
let entries = try infoFunction(fileData)
let entries = try ContainerType.info(container: fileData)
swcomp.printInfo(entries)
} else if let outputPath = self.extract.value {
if try !isValidOutputDirectory(outputPath, create: true) {
@@ -41,7 +38,7 @@ extension ContainerCommand {
exit(1)
}
let entries = try openFunction(fileData)
let entries = try ContainerType.open(container: fileData)
try swcomp.write(entries, outputPath, verbose.value)
}
}
+2 -3
View File
@@ -9,6 +9,8 @@ import SwiftCLI
class ZipCommand: ContainerCommand {
typealias ContainerType = ZipContainer
let name = "zip"
let shortDescription = "Extracts a ZIP container"
@@ -18,7 +20,4 @@ class ZipCommand: ContainerCommand {
let archive = Parameter()
let openFunction: (Data) throws -> [ZipEntry] = ZipContainer.open
let infoFunction: (Data) throws -> [ZipEntryInfo] = ZipContainer.info
}