Fix clippy linting errors

feature/lookup-installed
trivernis 2 years ago
parent 8b4383aaf3
commit 621f599e32
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -62,7 +62,7 @@ map_os!(
); );
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
pub const ARCHIVE_TYPE: &'static str = "tar.gz"; pub const ARCHIVE_TYPE: &str = "tar.gz";
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
pub const ARCHIVE_TYPE: &'static str = "zip"; pub const ARCHIVE_TYPE: &'static str = "zip";

@ -106,7 +106,7 @@ impl ParseTomlError {
.map(|p| SourceSpan::new(p.into(), 0.into())); .map(|p| SourceSpan::new(p.into(), 0.into()));
Self { Self {
src: NamedSource::new(file_name, src), src: NamedSource::new(file_name, src),
pos: abs_pos.into(), pos: abs_pos,
caused_by, caused_by,
} }
} }

@ -29,7 +29,10 @@ async fn main() -> Result<()> {
let args: Args = Args::parse(); let args: Args = Args::parse();
match args.commmand { match args.commmand {
args::Command::Version => Ok(print_version()), args::Command::Version => {
print_version();
Ok(())
},
args::Command::Install(v) => install_version(v.version).await, args::Command::Install(v) => install_version(v.version).await,
args::Command::Default(v) => set_default_version(v.version).await, args::Command::Default(v) => set_default_version(v.version).await,
args::Command::Exec(args) => { args::Command::Exec(args) => {
@ -56,19 +59,16 @@ pub async fn install_version(version: NodeVersion) -> Result<()> {
} }
let repo = get_repository().await?; let repo = get_repository().await?;
if repo.is_installed(&version)? { if repo.is_installed(&version)? && !Confirm::new()
if !Confirm::new()
.with_prompt(format!( .with_prompt(format!(
"The version {} is already installed. Reinstall?", "The version {} is already installed. Reinstall?",
version.to_string().bold() version.to_string().bold()
)) ))
.default(false) .default(false)
.interact() .interact()
.unwrap() .unwrap() {
{
return Ok(()); return Ok(());
} }
}
repo.install_version(&version).await?; repo.install_version(&version).await?;
println!("Installed {}", version.to_string().bold()); println!("Installed {}", version.to_string().bold());
@ -102,7 +102,7 @@ pub async fn exec(command: String, args: Vec<OsString>) -> Result<i32> {
let active_version = mapper.active_version(); let active_version = mapper.active_version();
if !mapper.repository().is_installed(active_version)? { if !mapper.repository().is_installed(active_version)? {
mapper.repository().install_version(&active_version).await?; mapper.repository().install_version(active_version).await?;
} }
let exit_status = mapper.exec(command, args).await?; let exit_status = mapper.exec(command, args).await?;

@ -56,7 +56,7 @@ impl NodeApp {
} }
pub async fn map_node_bin(node_path: NodePath) -> Result<()> { pub async fn map_node_bin(node_path: NodePath) -> Result<()> {
let mapped_app_names = get_applications(&*BIN_DIR) let mapped_app_names = get_applications(&BIN_DIR)
.await? .await?
.iter() .iter()
.map(NodeApp::name) .map(NodeApp::name)

@ -120,7 +120,7 @@ impl Repository {
/// Returns the path for the given node version /// Returns the path for the given node version
pub fn get_version_path(&self, version: &NodeVersion) -> Result<Option<NodePath>> { pub fn get_version_path(&self, version: &NodeVersion) -> Result<Option<NodePath>> {
let info = self.lookup_version(&version)?; let info = self.lookup_version(version)?;
let path = build_version_path(&info.version); let path = build_version_path(&info.version);
Ok(if path.exists() { Ok(if path.exists() {
@ -158,11 +158,11 @@ impl Repository {
NodeVersion::LatestLts => self.versions.latest_lts(), NodeVersion::LatestLts => self.versions.latest_lts(),
NodeVersion::Lts(lts) => self NodeVersion::Lts(lts) => self
.versions .versions
.get_lts(&lts) .get_lts(lts)
.ok_or_else(|| VersionError::unknown_version(lts.to_owned()))?, .ok_or_else(|| VersionError::unknown_version(lts.to_owned()))?,
NodeVersion::Req(req) => self NodeVersion::Req(req) => self
.versions .versions
.get_fulfilling(&req) .get_fulfilling(req)
.ok_or_else(|| VersionError::unfulfillable_version(req.to_owned()))?, .ok_or_else(|| VersionError::unfulfillable_version(req.to_owned()))?,
}; };
@ -176,7 +176,7 @@ impl Repository {
/// Installs a specified node version /// Installs a specified node version
pub async fn install_version(&self, version_req: &NodeVersion) -> Result<()> { pub async fn install_version(&self, version_req: &NodeVersion) -> Result<()> {
let info = self.lookup_version(&version_req)?; let info = self.lookup_version(version_req)?;
let archive_path = self.download_version(&info.version).await?; let archive_path = self.download_version(&info.version).await?;
self.extract_archive(info, &archive_path)?; self.extract_archive(info, &archive_path)?;

Loading…
Cancel
Save