(&self, _config: GlobalConfig)
| 33 | |
| 34 | impl Expand { |
| 35 | pub fn run(&self, _config: GlobalConfig) -> CliResult { |
| 36 | let Expand { content, output, check, semicolons, escape_idents } = self; |
| 37 | let bump = Bump::default(); |
| 38 | let start = std::time::Instant::now(); |
| 39 | if *check && output.is_some() { |
| 40 | eprintln!("Ignoring output option, because check was passed"); |
| 41 | } |
| 42 | let mut checks = 0; |
| 43 | for (file_name, mut source) in content.sources()? { |
| 44 | let mut source_string = String::new(); |
| 45 | source.read_to_string(&mut source_string)?; |
| 46 | let source_text = source_string.as_str(); |
| 47 | let lexer = Lexer::new(&CssAtomSet::ATOMS, source_text); |
| 48 | let mut parser = Parser::new(&bump, source_text, lexer); |
| 49 | let result = parser.parse_entirely::<StyleSheet>(); |
| 50 | if let Some(ref _stylesheet) = result.output { |
| 51 | let mut str = String::new(); |
| 52 | let mut stream = CursorExpandedWriteSink::new(source_text, &mut str) |
| 53 | .with_extra_semicolons(*semicolons) |
| 54 | .with_escape_idents(*escape_idents); |
| 55 | result.to_cursors(&mut stream); |
| 56 | if *check { |
| 57 | if str != source_text { |
| 58 | println!("{str}"); |
| 59 | checks += 1; |
| 60 | } |
| 61 | } else if let Some(file) = output { |
| 62 | std::fs::write(file, str.as_bytes())?; |
| 63 | } else { |
| 64 | println!("{str}"); |
| 65 | } |
| 66 | } else { |
| 67 | for compact_err in result.errors { |
| 68 | let report = crate::commands::format_diagnostic_error(&compact_err, &source_string, file_name); |
| 69 | println!("{report}"); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | eprintln!("Bloated your CSS in {:?}! Chunky!", start.elapsed()); |
| 74 | if checks > 0 { Err(CliError::Checks(checks))? } else { Ok(()) } |
| 75 | } |
| 76 | } |
nothing calls this directly
no test coverage detected