You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nenv/src/lib.rs

61 lines
1.5 KiB
Rust

use crossterm::style::Stylize;
use mapper::Mapper;
use repository::{config::Config, NodeVersion, Repository};
2 years ago
mod consts;
pub mod error;
pub mod mapper;
pub mod repository;
mod utils;
2 years ago
mod web_api;
use dialoguer::Confirm;
use error::Result;
2 years ago
pub async fn install_version(version: NodeVersion) -> Result<()> {
let repo = get_repository().await?;
if repo.is_installed(&version).await? {
if !Confirm::new()
.with_prompt("The version {version} is already installed. Reinstall?")
.default(false)
.interact()
.unwrap()
{
return Ok(());
}
}
repo.install_version(&version).await?;
println!("Installed {}", version.to_string().bold());
Ok(())
}
pub async fn use_version(version: NodeVersion) -> Result<()> {
let mut mapper = get_mapper().await?;
if !mapper.repository().is_installed(&version).await?
&& Confirm::new()
.with_prompt(format!(
"The version {version} is not installed. Do you want to install it?"
))
.default(false)
.interact()
.unwrap()
{
mapper.repository().install_version(&version).await?;
}
mapper.use_version(&version).await?;
println!("Now using {}", version.to_string().bold());
Ok(())
2 years ago
}
async fn get_repository() -> Result<Repository> {
Repository::init(Config::load().await?).await
}
async fn get_mapper() -> Result<Mapper> {
Ok(Mapper::new(get_repository().await?))
}