mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-30 09:05:54 +00:00
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:
2 files changed
+15
-2
No files matched your search
@@ -1,3 +1,9 @@
|
|||||||
|
# unreleased
|
||||||
|
|
||||||
|
## Bugfixes
|
||||||
|
|
||||||
|
- Throw an error when try to view a directory, see #234 (@Integral-Tech)
|
||||||
|
|
||||||
# v0.15.0
|
# v0.15.0
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|||||||
+9
-2
@@ -6,7 +6,7 @@ use std::path::PathBuf;
|
|||||||
use clap::builder::ArgPredicate;
|
use clap::builder::ArgPredicate;
|
||||||
use clap::{ArgAction, Parser, ValueEnum};
|
use clap::{ArgAction, Parser, ValueEnum};
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
|
|
||||||
use const_format::formatcp;
|
use const_format::formatcp;
|
||||||
|
|
||||||
@@ -234,7 +234,14 @@ fn run() -> Result<()> {
|
|||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
|
|
||||||
let mut reader = match opt.file {
|
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()),
|
None => Input::Stdin(stdin.lock()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user