@ -42,14 +42,13 @@ impl Command for Use {
system_version ::path ( )
system_version ::path ( )
} else if let Some ( alias_name ) = requested_version . alias_name ( ) {
} else if let Some ( alias_name ) = requested_version . alias_name ( ) {
let alias_path = config . aliases_dir ( ) . join ( & alias_name ) ;
let alias_path = config . aliases_dir ( ) . join ( & alias_name ) ;
ensure ! (
if alias_path . exists ( ) {
alias_path . exists ( ) ,
outln ! ( config #Info , "Using Node for alias {}" , alias_name . cyan ( ) ) ;
CantFindVersion {
alias_path
version : requested_version
} else {
}
install_new_version ( requested_version , config , self . install_if_missing ) ? ;
) ;
return Ok ( ( ) ) ;
outln ! ( config #Info , "Using Node for alias {}" , alias_name . cyan ( ) ) ;
}
alias_path
} else {
} else {
let current_version = requested_version . to_version ( & all_versions , & config ) ;
let current_version = requested_version . to_version ( & all_versions , & config ) ;
match current_version {
match current_version {
@ -61,26 +60,7 @@ impl Command for Use {
. join ( "installation" )
. join ( "installation" )
}
}
None = > {
None = > {
ensure ! (
install_new_version ( requested_version , config , self . install_if_missing ) ? ;
self . install_if_missing | | should_install_interactively ( & requested_version ) ,
CantFindVersion {
version : requested_version
}
) ;
Install {
version : Some ( requested_version . clone ( ) ) ,
.. Default ::default ( )
}
. apply ( config )
. context ( InstallError ) ? ;
Self {
version : Some ( UserVersionReader ::Direct ( requested_version ) ) ,
install_if_missing : self . install_if_missing ,
}
. apply ( config ) ? ;
return Ok ( ( ) ) ;
return Ok ( ( ) ) ;
}
}
}
}
@ -92,6 +72,34 @@ impl Command for Use {
}
}
}
}
fn install_new_version (
requested_version : UserVersion ,
config : & FnmConfig ,
install_if_missing : bool ,
) -> Result < ( ) , Error > {
ensure ! (
install_if_missing | | should_install_interactively ( & requested_version ) ,
CantFindVersion {
version : requested_version
}
) ;
Install {
version : Some ( requested_version . clone ( ) ) ,
.. Default ::default ( )
}
. apply ( config )
. context ( InstallError ) ? ;
Use {
version : Some ( UserVersionReader ::Direct ( requested_version ) ) ,
install_if_missing : true ,
}
. apply ( config ) ? ;
return Ok ( ( ) ) ;
}
/// Tries to delete `from`, and then tries to symlink `from` to `to` anyway.
/// Tries to delete `from`, and then tries to symlink `from` to `to` anyway.
/// If the symlinking fails, it will return the errors in the following order:
/// If the symlinking fails, it will return the errors in the following order:
/// * The deletion error (if exists)
/// * The deletion error (if exists)