From 15a99d144809541d3457e89e5a191ff27e75fc5b Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 19 Sep 2021 15:15:55 +0300 Subject: [PATCH] [swcomp] Replace ContainerCommand.Entry with ContainerType --- Sources/swcomp/Containers/7ZipCommand.swift | 5 ++--- Sources/swcomp/Containers/ContainerCommand.swift | 9 +++------ Sources/swcomp/Containers/ZipCommand.swift | 5 ++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Sources/swcomp/Containers/7ZipCommand.swift b/Sources/swcomp/Containers/7ZipCommand.swift index b96fbea9..f09f801f 100644 --- a/Sources/swcomp/Containers/7ZipCommand.swift +++ b/Sources/swcomp/Containers/7ZipCommand.swift @@ -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 - } diff --git a/Sources/swcomp/Containers/ContainerCommand.swift b/Sources/swcomp/Containers/ContainerCommand.swift index 32459532..a156d85d 100644 --- a/Sources/swcomp/Containers/ContainerCommand.swift +++ b/Sources/swcomp/Containers/ContainerCommand.swift @@ -9,7 +9,7 @@ import SwiftCLI protocol ContainerCommand: Command { - associatedtype Entry: ContainerEntry + associatedtype ContainerType: Container var info: Flag { get } var extract: Key { 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) } } diff --git a/Sources/swcomp/Containers/ZipCommand.swift b/Sources/swcomp/Containers/ZipCommand.swift index f104b072..3e5a04ea 100644 --- a/Sources/swcomp/Containers/ZipCommand.swift +++ b/Sources/swcomp/Containers/ZipCommand.swift @@ -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 - }