use std::ffi::OsString;
use crate::config::name::ProfileName;
use crate::config::store::StoreError;
use crate::error::Error;
use crate::git::repo::Repo;
use crate::git::runner::Git;
use super::args::UseArgs;
pub fn run(args: UseArgs, global_options: &[OsString]) -> Result<i32, Error> {
let name: ProfileName = args
.profile
.parse()
.map_err(|e| Error::msg(format!("{e}")))?;
let store = super::open_store()?;
if !store.profile_exists(&name) {
return Err(StoreError::NotFound(name).into());
}
Repo::new(Git::new(global_options)).set_profile(name.as_str())?;
println!("This repository now uses profile `{name}`.");
Ok(0)
}