Skip to content

Commit 6e0bff2

Browse files
authored
Merge pull request #234 from Integral-Tech/error-on-dir
fix: throw an error when try to view a directory
2 parents 1783fe6 + 19198c2 commit 6e0bff2

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# unreleased
2+
3+
## Bugfixes
4+
5+
- Throw an error when try to view a directory, see #234 (@Integral-Tech)
6+
17
# v0.15.0
28

39
## Features

src/main.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::PathBuf;
66
use clap::builder::ArgPredicate;
77
use clap::{ArgAction, Parser, ValueEnum};
88

9-
use anyhow::{anyhow, Context, Result};
9+
use anyhow::{anyhow, bail, Context, Result};
1010

1111
use const_format::formatcp;
1212

@@ -234,7 +234,14 @@ fn run() -> Result<()> {
234234
let stdin = io::stdin();
235235

236236
let mut reader = match opt.file {
237-
Some(filename) => Input::File(File::open(filename)?),
237+
Some(filename) => {
238+
if filename.is_dir() {
239+
bail!("'{}' is a directory.", filename.to_string_lossy());
240+
}
241+
let file = File::open(&filename)?;
242+
243+
Input::File(file)
244+
}
238245
None => Input::Stdin(stdin.lock()),
239246
};
240247

0 commit comments

Comments
 (0)