[swcomp] Add --format (-f) option to TarCommand which prints format of the container

This commit is contained in:
Timofey Solomko
2018-04-13 18:19:17 +03:00
parent 5a91fb2145
commit 7e04fe1fba
+15 -1
View File
@@ -18,12 +18,13 @@ class TarCommand: Command {
let info = Flag("-i", "--info", description: "Print list of entries in container and their attributes")
let extract = Key<String>("-e", "--extract", description: "Extract container into specified directory")
let format = Flag("-f", "--format", description: "Prints \"format\" of the container")
let verbose = Flag("--verbose", description: "Print the list of extracted files and directories.")
var optionGroups: [OptionGroup] {
let compressions = OptionGroup(options: [gz, bz2, xz], restriction: .atMostOne)
let actions = OptionGroup(options: [info, extract], restriction: .exactlyOne)
let actions = OptionGroup(options: [info, extract, format], restriction: .exactlyOne)
return [compressions, actions]
}
@@ -52,6 +53,19 @@ class TarCommand: Command {
let entries = try TarContainer.open(container: fileData)
try swcomp.write(entries, outputPath, verbose.value)
} else if format.value {
let format = try TarContainer.formatOf(container: fileData)
switch format {
case .prePosix:
print("TAR format: pre-POSIX")
case .ustar:
print("TAR format: POSIX aka \"ustar\"")
case .gnu:
print("TAR format: POSIX with GNU extensions")
case .pax:
print("TAR format: PAX")
}
}
}