mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
43 lines
1.2 KiB
Swift
43 lines
1.2 KiB
Swift
// Copyright (c) 2026 Timofey Solomko
|
|
// Licensed under MIT License
|
|
//
|
|
// See LICENSE for license information
|
|
|
|
import Foundation
|
|
import SWCompression
|
|
import SwiftCLI
|
|
|
|
protocol ContainerCommand: Command {
|
|
|
|
associatedtype ContainerType: Container
|
|
|
|
var info: Bool { get }
|
|
var list: Bool { get }
|
|
var extract: String? { get }
|
|
var verbose: Bool { get }
|
|
var input: String { get }
|
|
|
|
}
|
|
|
|
extension ContainerCommand {
|
|
|
|
func execute() throws {
|
|
let fileData = try Data(contentsOf: URL(fileURLWithPath: self.input),
|
|
options: .mappedIfSafe)
|
|
if info {
|
|
let entries = try ContainerType.info(container: fileData)
|
|
swcomp.printInfo(entries)
|
|
} else if list {
|
|
let entries = try ContainerType.info(container: fileData)
|
|
swcomp.printList(entries)
|
|
} else if let outputPath = self.extract {
|
|
guard try isValidOutputDirectory(outputPath, create: true)
|
|
else { swcompExit(.containerOutPathExistsNotDir) }
|
|
|
|
let entries = try ContainerType.open(container: fileData)
|
|
try swcomp.write(entries, outputPath, verbose)
|
|
}
|
|
}
|
|
|
|
}
|