Skip to content

Commit f5f36cb

Browse files
committed
Support short channel matching
1 parent 17085a5 commit f5f36cb

File tree

2 files changed

+72
-16
lines changed

2 files changed

+72
-16
lines changed

src/bin/julialauncher.rs

+34-16
Original file line numberDiff line numberDiff line change
@@ -166,32 +166,47 @@ fn get_julia_path_from_channel(
166166
juliaupconfig_path: &Path,
167167
juliaup_channel_source: JuliaupChannelSource,
168168
) -> Result<(PathBuf, Vec<String>)> {
169+
let potential_matches: Vec<_> = config_data
170+
.installed_channels
171+
.keys()
172+
.filter(|&item| item.starts_with(channel))
173+
.cloned()
174+
.collect();
175+
let actualchannel = if potential_matches.len() == 1 {
176+
potential_matches
177+
.first()
178+
.expect("length should be 1")
179+
.as_str()
180+
} else {
181+
channel
182+
};
183+
169184
let channel_info = config_data
170185
.installed_channels
171-
.get(channel)
186+
.get(actualchannel)
172187
.ok_or_else(|| match juliaup_channel_source {
173188
JuliaupChannelSource::CmdLine => {
174-
if versions_db.available_channels.contains_key(channel) {
175-
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
189+
if versions_db.available_channels.contains_key(actualchannel) {
190+
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", actualchannel, actualchannel) }
176191
} else {
177-
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
192+
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", actualchannel) }
178193
}
179194
}.into(),
180195
JuliaupChannelSource::EnvVar=> {
181-
if versions_db.available_channels.contains_key(channel) {
182-
UserError { msg: format!("`{}` for environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
196+
if versions_db.available_channels.contains_key(actualchannel) {
197+
UserError { msg: format!("`{}` for environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", actualchannel, actualchannel) }
183198
} else {
184-
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) }
199+
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) }
185200
}
186201
}.into(),
187202
JuliaupChannelSource::Override=> {
188-
if versions_db.available_channels.contains_key(channel) {
189-
UserError { msg: format!("`{}` for directory override is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
203+
if versions_db.available_channels.contains_key(actualchannel) {
204+
UserError { msg: format!("`{}` for directory override is not installed. Please run `juliaup add {}` to install channel or version.", actualchannel, actualchannel) }
190205
} else {
191-
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in directory override. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
206+
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in directory override. Please run `juliaup list` to get a list of valid channels and versions.", actualchannel) }
192207
}
193208
}.into(),
194-
JuliaupChannelSource::Default => anyhow!("The Juliaup configuration is in an inconsistent state, the currently configured default channel `{}` is not installed.", channel)
209+
JuliaupChannelSource::Default => anyhow!("The Juliaup configuration is in an inconsistent state, the currently configured default channel `{}` is not installed.", actualchannel)
195210
})?;
196211

197212
match channel_info {
@@ -204,12 +219,12 @@ fn get_julia_path_from_channel(
204219
JuliaupConfigChannel::SystemChannel { version } => {
205220
let path = &config_data
206221
.installed_versions.get(version)
207-
.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;
222+
.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;
208223

209-
check_channel_uptodate(channel, version, versions_db).with_context(|| {
224+
check_channel_uptodate(actualchannel, version, versions_db).with_context(|| {
210225
format!(
211226
"The Julia launcher failed while checking whether the channel {} is up-to-date.",
212-
channel
227+
actualchannel
213228
)
214229
})?;
215230
let absolute_path = juliaupconfig_path
@@ -237,12 +252,15 @@ fn get_julia_path_from_channel(
237252
if local_etag != server_etag {
238253
eprintln!(
239254
"A new version of Julia for the `{}` channel is available. Run:",
240-
channel
255+
actualchannel
241256
);
242257
eprintln!();
243258
eprintln!(" juliaup update");
244259
eprintln!();
245-
eprintln!("to install the latest Julia for the `{}` channel.", channel);
260+
eprintln!(
261+
"to install the latest Julia for the `{}` channel.",
262+
actualchannel
263+
);
246264
}
247265

248266
let absolute_path = juliaupconfig_path

tests/channel_selection.rs

+38
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,42 @@ fn channel_selection() {
125125
.assert()
126126
.failure()
127127
.stderr("ERROR: Invalid Juliaup channel `1.8.6`. Please run `juliaup list` to get a list of valid channels and versions.\n");
128+
129+
// Now testing short channel matching
130+
131+
Command::cargo_bin("julia")
132+
.unwrap()
133+
.arg("+1.8")
134+
.arg("-e")
135+
.arg("print(VERSION)")
136+
.env("JULIA_DEPOT_PATH", depot_dir.path())
137+
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
138+
.env("JULIAUP_CHANNEL", "1.7.3")
139+
.assert()
140+
.success()
141+
.stdout("1.8.5");
142+
143+
Command::cargo_bin("juliaup")
144+
.unwrap()
145+
.arg("add")
146+
.arg("1.8.4")
147+
.env("JULIA_DEPOT_PATH", depot_dir.path())
148+
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
149+
.assert()
150+
.success()
151+
.stdout("");
152+
153+
Command::cargo_bin("julia")
154+
.unwrap()
155+
.arg("+1.8")
156+
.arg("-e")
157+
.arg("print(VERSION)")
158+
.env("JULIA_DEPOT_PATH", depot_dir.path())
159+
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
160+
.env("JULIAUP_CHANNEL", "1.7.4")
161+
.assert()
162+
.failure()
163+
.stderr(
164+
"`1.8` is not installed. Please run `juliaup add 1.8` to install channel or version.\n",
165+
);
128166
}

0 commit comments

Comments
 (0)