feat: handle standard input "-" (#257)

This commit is contained in:
n4n5 authored and GitHub committed 2026-02-14 13:33:23 +01:00
1 parent 96e427cb4a
commit 04d74bae47
1 file changed
+21 -15
+21 -15
View File
@@ -284,12 +284,16 @@ fn run() -> Result<()> {
let mut reader = match &opt.file { let mut reader = match &opt.file {
Some(filename) => { Some(filename) => {
if filename.is_dir() { if filename.as_os_str() == "-" {
bail!("'{}' is a directory.", filename.to_string_lossy()); Input::Stdin(stdin.lock())
} } else {
let file = File::open(filename)?; if filename.is_dir() {
bail!("'{}' is a directory.", filename.to_string_lossy());
}
let file = File::open(filename)?;
Input::File(file) Input::File(file)
}
} }
None => Input::Stdin(stdin.lock()), None => Input::Stdin(stdin.lock()),
}; };
@@ -472,17 +476,19 @@ fn run() -> Result<()> {
let include_mode = match opt.include_mode { let include_mode = match opt.include_mode {
// include mode on // include mode on
true => { true => {
if opt.file.is_some() { if let Some(include_file) = opt.file {
// input from a file // input from a file
IncludeMode::File( if include_file.as_os_str() == "-" {
opt.file IncludeMode::File("stdin".to_string())
.as_ref() } else {
.unwrap() IncludeMode::File(
.file_name() include_file
.and_then(|n| n.to_str()) .file_name()
.unwrap_or("file") .and_then(|n| n.to_str())
.to_string(), .unwrap_or("file")
) .to_string(),
)
}
} else { } else {
// input from stdin // input from stdin
IncludeMode::Stdin IncludeMode::Stdin