Merge pull request #234 from Integral-Tech/error-on-dir

fix: throw an error when try to view a directory
This commit is contained in:
David Peter authored and GitHub committed 2024-12-27 14:29:34 +01:00
commit 6e0bff2cc5
2 files changed
+15 -2

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
+9 -2
View File
@@ -6,7 +6,7 @@ use std::path::PathBuf;
use clap::builder::ArgPredicate;
use clap::{ArgAction, Parser, ValueEnum};
use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, bail, Context, Result};
use const_format::formatcp;
@@ -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) => {
if filename.is_dir() {
bail!("'{}' is a directory.", filename.to_string_lossy());
}
let file = File::open(&filename)?;
Input::File(file)
}
None => Input::Stdin(stdin.lock()),
};