(args: &[String], _cwd: &Path)
| 38 | Android, |
| 39 | } |
| 40 | |
| 41 | pub(crate) fn clean_command(args: &[String], _cwd: &Path) -> Result<(), String> { |
| 42 | let project_dir = parse_flag_value(args, "--path") |
| 43 | .map(|p| resolve_local_path(&p, _cwd)) |
| 44 | .or_else(|| find_project_root(_cwd)) |
| 45 | .ok_or_else(|| { |
| 46 | "could not find project.toml. Run from a project directory or pass --path <project_dir>." |
| 47 | .to_string() |
| 48 | })?; |
| 49 | let project_dir = project_dir.canonicalize().unwrap_or(project_dir); |
| 50 | if !project_dir.join("project.toml").exists() { |
| 51 | return Err(format!( |
| 52 | "invalid --path `{}` for clean. Use project root (directory containing project.toml).", |
| 53 | project_dir.display() |
| 54 | )); |
| 55 | } |
| 56 | |
| 57 | let target_dir = project_dir.join("target"); |
| 58 | if !target_dir.exists() { |
| 59 | log_note("No project target/ directory to clean"); |
| 60 | return Ok(()); |
| 61 | } |
| 62 | |
| 63 | if let Ok(current_exe) = env::current_exe() |
| 64 | && current_exe.starts_with(&target_dir) |
| 65 | { |
| 66 | return Err( |
| 67 | "cannot clean while running from the project's target/. Use the installed `perro` command or run from another location." |
| 68 | .to_string(), |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | log_step("Cleaning Project Target"); |
| 73 | fs::remove_dir_all(&target_dir) |
| 74 | .map_err(|err| format!("failed to remove {}: {err}", target_dir.display()))?; |
| 75 | log_done("Project Target Cleaned"); |
| 76 | Ok(()) |
| 77 | } |
| 78 | |
| 79 | pub(crate) fn maybe_open_file_in_editor(args: &[String], file_path: &Path) -> Result<(), String> { |
no test coverage detected