application.nct
see ./index.nct
use std/io.BlockingFile
use std/io
use std/cli.Application
use std/path.Utf8Path
use std/string.String
blocking func print_report(report: &ArchiveReport): void! {
var index: usize = 0
while index < report.entry_count() {
let path = report.entry_path(index) otherwise { return error.new("archive-inspect.invalid_report", "entry path is absent") }
let size = report.entry_size(index) otherwise { return error.new("archive-inspect.invalid_report", "entry size is absent") }
let directory = report.entry_is_directory(index) otherwise { return error.new("archive-inspect.invalid_report", "entry kind is absent") }
let kind = if directory { "directory" } else { "file" }
let size_text = size.to_string()
let line = String.concat(kind, "\t", &size_text, "\t", path, "\n")
io.print(&line)?
index += 1
}
return
}
blocking func main(): i32 {
var application = Application.new("archive-inspect", "Inspect one gzip-compressed tar archive.") catch _ { return 2 }
application.add_positional("ARCHIVE.tar.gz", true, "Archive path.") catch _ { return 2 }
let arguments = application.parse_process() catch _ {
let usage = application.usage()
io.eprint(&usage) catch _ {}
io.eprint("\n") catch _ {}
return 2
}
let requested = arguments.positional("ARCHIVE.tar.gz") otherwise { return 2 }
let path = Utf8Path.new(requested) catch _ { return 2 }
let source = BlockingFile.open(&path) catch _ { return 1 }
let report = inspect(move source, ArchiveLimits.standard()) catch _ { return 1 }
print_report(&report) catch _ { return 1 }
return 0
}