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

Function clean_command

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

Source from the content-addressed store, hash-verified

38 Android,
39}
40
41pub(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
79pub(crate) fn maybe_open_file_in_editor(args: &[String], file_path: &Path) -> Result<(), String> {

Callers 1

mainFunction · 0.85

Calls 7

find_project_rootFunction · 0.85
log_noteFunction · 0.85
log_stepFunction · 0.85
log_doneFunction · 0.85
joinMethod · 0.80
parse_flag_valueFunction · 0.70
resolve_local_pathFunction · 0.70

Tested by

no test coverage detected