(args: &[String], cwd: &Path)
| 483 | } |
| 484 | } |
| 485 | |
| 486 | fn 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 | |
| 497 | pub(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(()) |
no test coverage detected