use crate::cli::LibCommand;
use crate::error::Result;
use crate::library::Registry;
pub fn run(command: LibCommand) -> Result<()> {
let mut registry = Registry::load()?;
match command {
LibCommand::Add { name, path } => {
let path = if path.is_absolute() {
path
} else {
std::env::current_dir()?.join(path)
};
registry.add(&name, path.clone())?;
registry.save()?;
println!("added library '{name}' -> {}", path.display());
}
LibCommand::List => {
if registry.libraries.is_empty() {
println!("no libraries registered");
}
for (name, path) in ®istry.libraries {
let marker = if registry.current.as_deref() == Some(name) { "*" } else { " " };
println!("{marker} {name}\t{}", path.display());
}
}
LibCommand::Use { name } => {
registry.use_library(&name)?;
registry.save()?;
println!("active library: {name}");
}
LibCommand::Current => {
let (name, path) = registry.current_library()?;
println!("{name}\t{}", path.display());
}
LibCommand::Remove { name } => {
registry.remove(&name)?;
registry.save()?;
println!("removed library '{name}' (files kept on disk)");
}
}
Ok(())
}