Run the command: loop files, parse, extract, render.
(&self, config: GlobalConfig)
| 179 | |
| 180 | /// Run the command: loop files, parse, extract, render. |
| 181 | fn run(&self, config: GlobalConfig) -> CliResult { |
| 182 | let bump = Bump::default(); |
| 183 | let mut envelopes: Vec<FileEnvelope<Self::Row>> = Vec::new(); |
| 184 | let mut first_file = true; |
| 185 | |
| 186 | for (filename, mut source) in self.input().sources()? { |
| 187 | let mut src = String::new(); |
| 188 | if let Err(e) = source.read_to_string(&mut src) { |
| 189 | match self.format() { |
| 190 | OutputFormat::Json => { |
| 191 | envelopes.push(FileEnvelope::err( |
| 192 | filename, |
| 193 | ErrorRecord { kind: ErrorKind::Io, message: e.to_string() }, |
| 194 | )); |
| 195 | } |
| 196 | OutputFormat::Text => { |
| 197 | eprintln!("{filename}: {e}"); |
| 198 | } |
| 199 | } |
| 200 | continue; |
| 201 | } |
| 202 | |
| 203 | let mut ctx = Self::FileContext::default(); |
| 204 | let mut on_stylesheet = |ss: &StyleSheet| { |
| 205 | if matches!(self.format(), OutputFormat::Text) { |
| 206 | ctx = self.build_context(ss, &src); |
| 207 | } |
| 208 | }; |
| 209 | |
| 210 | match self.parse_and_extract_file(filename, &src, &bump, &mut on_stylesheet) { |
| 211 | Ok(rows) => match self.format() { |
| 212 | OutputFormat::Text => { |
| 213 | if rows.is_empty() { |
| 214 | self.on_no_results(filename); |
| 215 | } else { |
| 216 | if !first_file { |
| 217 | println!(); |
| 218 | } |
| 219 | first_file = false; |
| 220 | if self.show_file_header() { |
| 221 | if config.colors() { |
| 222 | println!("{}", crate::magenta(filename)); |
| 223 | } else { |
| 224 | println!("{}", filename); |
| 225 | } |
| 226 | } |
| 227 | self.render_file_preamble(filename, rows.len(), config.colors()); |
| 228 | for (span, row) in &rows { |
| 229 | self.render_text(&ctx, filename, &src, *span, row, config.colors()); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | OutputFormat::Json => { |
| 234 | let records = rows |
| 235 | .into_iter() |
| 236 | .map(|(span, data)| Record { location: Location::from_span(span, &src), data }) |
| 237 | .collect(); |
| 238 | envelopes.push(FileEnvelope::ok(filename, records)); |
nothing calls this directly
no test coverage detected