aico/commands/
trust.rs

1use crate::exceptions::AicoError;
2use crate::trust;
3use std::env;
4use std::path::PathBuf;
5
6pub fn run(path: Option<PathBuf>, revoke: bool, show_list: bool) -> Result<(), AicoError> {
7    if show_list {
8        let projects = trust::list_trusted_projects();
9        if projects.is_empty() {
10            println!("No projects are currently trusted.");
11        } else {
12            println!("Trusted projects:");
13            for p in projects {
14                println!("  - {}", p);
15            }
16        }
17        return Ok(());
18    }
19
20    let target_path = match path {
21        Some(p) => p,
22        None => env::current_dir()?,
23    };
24
25    if revoke {
26        if trust::untrust_project(&target_path)? {
27            println!("Revoked trust for: {}", target_path.display());
28        } else {
29            println!("Path was not trusted: {}", target_path.display());
30        }
31    } else {
32        trust::trust_project(&target_path)?;
33        println!("Success: Trusted project: {}", target_path.display());
34        println!("Local addons in .aico/addons/ will now be loaded.");
35    }
36
37    Ok(())
38}