@ -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 ( ) ,
CantFindVersion {
version : requested_version
}
) ;
outln ! ( config #Info , "Using Node for alias {}" , alias_name . cyan ( ) ) ;
outln ! ( config #Info , "Using Node for alias {}" , alias_name . cyan ( ) ) ;
alias_path
alias_path
} else {
install_new_version ( requested_version , config , self . install_if_missing ) ? ;
return Ok ( ( ) ) ;
}
} 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,8 +60,25 @@ impl Command for Use {
. join ( "installation" )
. join ( "installation" )
}
}
None = > {
None = > {
install_new_version ( requested_version , config , self . install_if_missing ) ? ;
return Ok ( ( ) ) ;
}
}
} ;
replace_symlink ( & version_path , & multishell_path ) . context ( SymlinkingCreationIssue ) ? ;
Ok ( ( ) )
}
}
fn install_new_version (
requested_version : UserVersion ,
config : & FnmConfig ,
install_if_missing : bool ,
) -> Result < ( ) , Error > {
ensure ! (
ensure ! (
self . install_if_missing | | should_install_interactively ( & requested_version ) ,
install_if_missing | | should_install_interactively ( & requested_version ) ,
CantFindVersion {
CantFindVersion {
version : requested_version
version : requested_version
}
}
@ -75,21 +91,13 @@ impl Command for Use {
. apply ( config )
. apply ( config )
. context ( InstallError ) ? ;
. context ( InstallError ) ? ;
Self {
Use {
version : Some ( UserVersionReader ::Direct ( requested_version ) ) ,
version : Some ( UserVersionReader ::Direct ( requested_version ) ) ,
install_if_missing : self . install_if_missing ,
install_if_missing : true ,
}
}
. apply ( config ) ? ;
. apply ( config ) ? ;
return Ok ( ( ) ) ;
return Ok ( ( ) ) ;
}
}
} ;
replace_symlink ( & version_path , & multishell_path ) . context ( SymlinkingCreationIssue ) ? ;
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.