|
1 |
| -use std::io::Write; |
| 1 | +use std::io::{BufRead as _, BufReader, Write as _}; |
| 2 | +use std::path::PathBuf; |
2 | 3 |
|
3 | 4 | use clap::Parser;
|
4 | 5 |
|
@@ -167,8 +168,34 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
|
167 | 168 |
|
168 | 169 | let mut typos_found = false;
|
169 | 170 | let mut errors_found = false;
|
170 |
| - for path in args.path.iter() { |
| 171 | + |
| 172 | + let file_list = match args.file_list.as_deref() { |
| 173 | + Some(dash) if dash == PathBuf::from("-") => Some( |
| 174 | + std::io::stdin() |
| 175 | + .lines() |
| 176 | + .map(|res| res.map(PathBuf::from)) |
| 177 | + .collect::<Result<_, _>>() |
| 178 | + .with_code(proc_exit::sysexits::IO_ERR)?, |
| 179 | + ), |
| 180 | + Some(path) => Some( |
| 181 | + BufReader::new(std::fs::File::open(path).with_code(proc_exit::sysexits::IO_ERR)?) |
| 182 | + .lines() |
| 183 | + .map(|res| res.map(PathBuf::from)) |
| 184 | + .collect::<Result<_, _>>() |
| 185 | + .with_code(proc_exit::sysexits::IO_ERR)?, |
| 186 | + ), |
| 187 | + None => None, |
| 188 | + }; |
| 189 | + |
| 190 | + // Note: file_list and args.path are mutually exclusive, enforced by clap |
| 191 | + for path in file_list.as_ref().unwrap_or(&args.path) { |
| 192 | + // Note paths are passed through stdin, `-` is treated like a normal path |
171 | 193 | let cwd = if path == std::path::Path::new("-") {
|
| 194 | + if args.file_list.is_some() { |
| 195 | + return Err(proc_exit::sysexits::USAGE_ERR.with_message( |
| 196 | + "Can't use `-` (stdin) while using `--file_list` provided paths", |
| 197 | + )); |
| 198 | + }; |
172 | 199 | global_cwd.clone()
|
173 | 200 | } else if path.is_file() {
|
174 | 201 | let mut cwd = path
|
|
0 commit comments