Skip to content

Commit

Permalink
feat: show error when no input file specified
Browse files Browse the repository at this point in the history
Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
  • Loading branch information
wfxr committed Apr 3, 2024
1 parent 065bd76 commit 1214c96
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 44 deletions.
131 changes: 87 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ anyhow = "1.0"
unicode-width = "0"
unicode-truncate = "0"
itertools = "0.12"
atty = "0.2"

[build-dependencies]
clap = { version = "4", features = ["wrap_help", "derive"] }
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod cli;
mod table;
mod util;

use anyhow::bail;
use clap::Parser;
use cli::App;
use csv::{ErrorKind, ReaderBuilder};
Expand Down Expand Up @@ -76,6 +77,7 @@ fn try_main() -> anyhow::Result<()> {
.has_headers(!no_headers)
.from_reader(match file {
Some(path) => Box::new(File::open(path)?) as Box<dyn Read>,
None if atty::is(atty::Stream::Stdin) => bail!("no input file specified (use -h for help)"),
None => Box::new(io::stdin()),
});

Expand Down

0 comments on commit 1214c96

Please sign in to comment.