diff --git a/src/bin/julialauncher.rs b/src/bin/julialauncher.rs index 62c1ce17..5c0bc6b5 100644 --- a/src/bin/julialauncher.rs +++ b/src/bin/julialauncher.rs @@ -166,32 +166,42 @@ fn get_julia_path_from_channel( juliaupconfig_path: &Path, juliaup_channel_source: JuliaupChannelSource, ) -> Result<(PathBuf, Vec)> { + let potential_matches: Vec<_> = config_data.installed_channels.keys() + .filter(|&item| item.starts_with(channel)) + .cloned() + .collect(); + let actualchannel = if potential_matches.len() == 1 { + potential_matches.first().expect("length should be 1").as_str() + } else { + channel + }; + let channel_info = config_data .installed_channels - .get(channel) + .get(actualchannel) .ok_or_else(|| match juliaup_channel_source { JuliaupChannelSource::CmdLine => { - if versions_db.available_channels.contains_key(channel) { - UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) } + if versions_db.available_channels.contains_key(actualchannel) { + UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", actualchannel, actualchannel) } } else { - UserError { msg: format!("ERROR: Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", channel) } + UserError { msg: format!("ERROR: Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", actualchannel) } } }.into(), JuliaupChannelSource::EnvVar=> { - if versions_db.available_channels.contains_key(channel) { - UserError { msg: format!("`{}` for environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) } + if versions_db.available_channels.contains_key(actualchannel) { + UserError { msg: format!("`{}` for environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", actualchannel, actualchannel) } } else { - UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.", channel) } + UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.", actualchannel) } } }.into(), JuliaupChannelSource::Override=> { - if versions_db.available_channels.contains_key(channel) { - UserError { msg: format!("`{}` for directory override is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) } + if versions_db.available_channels.contains_key(actualchannel) { + UserError { msg: format!("`{}` for directory override is not installed. Please run `juliaup add {}` to install channel or version.", actualchannel, actualchannel) } } else { - UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in directory override. Please run `juliaup list` to get a list of valid channels and versions.", channel) } + UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in directory override. Please run `juliaup list` to get a list of valid channels and versions.", actualchannel) } } }.into(), - JuliaupChannelSource::Default => anyhow!("The Juliaup configuration is in an inconsistent state, the currently configured default channel `{}` is not installed.", channel) + JuliaupChannelSource::Default => anyhow!("The Juliaup configuration is in an inconsistent state, the currently configured default channel `{}` is not installed.", actualchannel) })?; match channel_info { @@ -204,12 +214,12 @@ fn get_julia_path_from_channel( JuliaupConfigChannel::SystemChannel { version } => { let path = &config_data .installed_versions.get(version) - .ok_or_else(|| anyhow!("The juliaup configuration is in an inconsistent state, the channel {} is pointing to Julia version {}, which is not installed.", channel, version))?.path; + .ok_or_else(|| anyhow!("The juliaup configuration is in an inconsistent state, the channel {} is pointing to Julia version {}, which is not installed.", actualchannel, version))?.path; - check_channel_uptodate(channel, version, versions_db).with_context(|| { + check_channel_uptodate(actualchannel, version, versions_db).with_context(|| { format!( "The Julia launcher failed while checking whether the channel {} is up-to-date.", - channel + actualchannel ) })?; let absolute_path = juliaupconfig_path @@ -237,12 +247,12 @@ fn get_julia_path_from_channel( if local_etag != server_etag { eprintln!( "A new version of Julia for the `{}` channel is available. Run:", - channel + actualchannel ); eprintln!(); eprintln!(" juliaup update"); eprintln!(); - eprintln!("to install the latest Julia for the `{}` channel.", channel); + eprintln!("to install the latest Julia for the `{}` channel.", actualchannel); } let absolute_path = juliaupconfig_path diff --git a/tests/channel_selection.rs b/tests/channel_selection.rs index 7af73a4a..30c0470b 100644 --- a/tests/channel_selection.rs +++ b/tests/channel_selection.rs @@ -125,4 +125,41 @@ fn channel_selection() { .assert() .failure() .stderr("ERROR: Invalid Juliaup channel `1.8.6`. Please run `juliaup list` to get a list of valid channels and versions.\n"); + + + // Now testing short channel matching + + Command::cargo_bin("julia") + .unwrap() + .arg("+1.8") + .arg("-e") + .arg("print(VERSION)") + .env("JULIA_DEPOT_PATH", depot_dir.path()) + .env("JULIAUP_DEPOT_PATH", depot_dir.path()) + .env("JULIAUP_CHANNEL", "1.7.3") + .assert() + .success() + .stdout("1.8.5"); + + Command::cargo_bin("juliaup") + .unwrap() + .arg("add") + .arg("1.8.4") + .env("JULIA_DEPOT_PATH", depot_dir.path()) + .env("JULIAUP_DEPOT_PATH", depot_dir.path()) + .assert() + .success() + .stdout(""); + + Command::cargo_bin("julia") + .unwrap() + .arg("+1.8") + .arg("-e") + .arg("print(VERSION)") + .env("JULIA_DEPOT_PATH", depot_dir.path()) + .env("JULIAUP_DEPOT_PATH", depot_dir.path()) + .env("JULIAUP_CHANNEL", "1.7.4") + .assert() + .failure() + .stderr("`1.8` is not installed. Please run `juliaup add 1.8` to install channel or version.\n"); }