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
+10 -4
+10 -4
View File
@@ -284,6 +284,9 @@ fn run() -> Result<()> {
let mut reader = match &opt.file { let mut reader = match &opt.file {
Some(filename) => { Some(filename) => {
if filename.as_os_str() == "-" {
Input::Stdin(stdin.lock())
} else {
if filename.is_dir() { if filename.is_dir() {
bail!("'{}' is a directory.", filename.to_string_lossy()); bail!("'{}' is a directory.", filename.to_string_lossy());
} }
@@ -291,6 +294,7 @@ fn run() -> Result<()> {
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
if include_file.as_os_str() == "-" {
IncludeMode::File("stdin".to_string())
} else {
IncludeMode::File( IncludeMode::File(
opt.file include_file
.as_ref()
.unwrap()
.file_name() .file_name()
.and_then(|n| n.to_str()) .and_then(|n| n.to_str())
.unwrap_or("file") .unwrap_or("file")
.to_string(), .to_string(),
) )
}
} else { } else {
// input from stdin // input from stdin
IncludeMode::Stdin IncludeMode::Stdin