Skip to content

Commit

Permalink
Merge pull request #234 from Integral-Tech/error-on-dir
Browse files Browse the repository at this point in the history
fix: throw an error when try to view a directory
  • Loading branch information
sharkdp authored Dec 27, 2024
2 parents 1783fe6 + 19198c2 commit 6e0bff2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# unreleased

## Bugfixes

- Throw an error when try to view a directory, see #234 (@Integral-Tech)

# v0.15.0

## Features
Expand Down
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()),
};

Expand Down

0 comments on commit 6e0bff2

Please sign in to comment.