fix: throw an error when try to view a directory

This commit is contained in:
Integral committed 2024-11-21 00:55:37 +08:00
1 parent dbed12e423
commit c65b298e60
2 files changed
+14 -1

No files matched your search

+6
View File
@@ -1,3 +1,9 @@
# unreleased
## Bugfixes
- Throw an error when try to view a directory, see #234 (@Integral-Tech)
# v0.15.0
## Features
+8 -1
View File
@@ -234,7 +234,14 @@ fn run() -> Result<()> {
let stdin = io::stdin();
let mut reader = match opt.file {
Some(filename) => Input::File(File::open(filename)?),
Some(filename) => {
let file = File::open(&filename)?;
if file.metadata()?.is_dir() {
return Err(anyhow!("{} is a directory.", filename.display()));
}
Input::File(file)
}
None => Input::Stdin(stdin.lock()),
};