MCPcopy Create free account
hub / github.com/csskit/csskit / run

Method run

crates/csskit/src/commands/build.rs:22–52  ·  view source on GitHub ↗
(&self, _config: GlobalConfig)

Source from the content-addressed store, hash-verified

20
21impl Build {
22 pub fn run(&self, _config: GlobalConfig) -> CliResult {
23 let Build { content, output } = self;
24 let bump = Bump::default();
25 let mut str = String::new();
26 let start = std::time::Instant::now();
27 for (file_name, mut source) in content.sources()? {
28 let mut source_string = String::new();
29 source.read_to_string(&mut source_string)?;
30 let source_text = source_string.as_str();
31 let lexer = Lexer::new(&CssAtomSet::ATOMS, source_text);
32 let mut parser = Parser::new(&bump, source_text, lexer);
33 let result = parser.parse_entirely::<StyleSheet>();
34 if result.output.is_some() {
35 let mut stream = CursorCompactWriteSink::new(source_text, &mut str);
36 result.with_trivia().to_cursors(&mut stream);
37 } else {
38 for compact_err in result.errors {
39 let report = crate::commands::format_diagnostic_error(&compact_err, &source_string, file_name);
40 println!("{report}");
41 }
42 Err(CliError::ParseFailed)?;
43 }
44 }
45 if let Some(file) = output {
46 std::fs::write(file, str.as_bytes())?;
47 } else {
48 println!("{str}");
49 }
50 eprintln!("Slurped up CSS in {:?}! Neat!", start.elapsed());
51 Ok(())
52 }
53}

Callers

nothing calls this directly

Calls 6

format_diagnostic_errorFunction · 0.85
ErrClass · 0.85
sourcesMethod · 0.80
with_triviaMethod · 0.80
as_strMethod · 0.45
to_cursorsMethod · 0.45

Tested by

no test coverage detected