MCPcopy Create free account
hub / github.com/PerroEngine/Perro / clippy_command

Function clippy_command

perro_source/devtools/perro_cli/src/project.rs:485–538  ·  view source on GitHub ↗
(args: &[String], cwd: &Path)

Source from the content-addressed store, hash-verified

483 }
484}
485
486fn find_steam_runtime_library(build_dir: &Path, library_name: &str) -> Option<PathBuf> {
487 let entries = fs::read_dir(build_dir).ok()?;
488 for entry in entries.flatten() {
489 let path = entry.path().join("out").join(library_name);
490 if path.exists() {
491 return Some(path);
492 }
493 }
494 None
495}
496
497pub(crate) fn format_command(args: &[String], cwd: &Path) -> Result<(), String> {
498 let base_path = parse_flag_value(args, "--path")
499 .map(|p| resolve_local_path(&p, cwd))
500 .unwrap_or_else(|| cwd.to_path_buf());
501 let base_path = base_path.canonicalize().unwrap_or(base_path);
502 let res_dir = resolve_project_res_root(&base_path, "format")?;
503 let dedup = args.iter().any(|arg| arg == "--dedup");
504 let mut script_files = Vec::new();
505 collect_rs_files_recursive(&res_dir, &mut script_files)?;
506 let mut asset_files = Vec::new();
507 collect_format_asset_files_recursive(&res_dir, &mut asset_files)?;
508
509 if script_files.is_empty() && asset_files.is_empty() {
510 log_note("No format targets found under res");
511 return Ok(());
512 }
513
514 if !script_files.is_empty() {
515 log_step("Formatting User Scripts");
516 for file in &script_files {
517 let status = Command::new("rustfmt")
518 .arg("--edition")
519 .arg("2024")
520 .arg(file)
521 .status()
522 .map_err(|err| format!("failed to run rustfmt for {}: {err}", file.display()))?;
523 if !status.success() {
524 return Err(format!(
525 "rustfmt failed for {} with exit code {:?}",
526 file.display(),
527 status.code()
528 ));
529 }
530 }
531 log_done("User Scripts Formatted");
532 }
533
534 if !asset_files.is_empty() {
535 log_step("Formatting Resource Files");
536 for file in &asset_files {
537 format_asset_file(file, dedup)?;
538 }
539 log_done("Resource Files Formatted");
540 }
541 Ok(())

Callers 1

mainFunction · 0.85

Calls 12

resolve_project_res_rootFunction · 0.85
log_noteFunction · 0.85
log_stepFunction · 0.85
ensure_source_overridesFunction · 0.85
sync_scriptsFunction · 0.85
log_doneFunction · 0.85
joinMethod · 0.80
parse_flag_valueFunction · 0.70
resolve_local_pathFunction · 0.70
is_emptyMethod · 0.45

Tested by

no test coverage detected