Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support overriding an override #1002

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions src/command_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ pub fn run_command_override_set(
.with_context(|| "`override set` command failed to load configuration data.")?;

if !config_file.data.installed_channels.contains_key(&channel) {
bail!("'{}' channel does not exist.", &channel);
bail!(
"'{}' is not installed. Please run `juliaup add {}` to install channel or version.",
&channel,
&channel
);
}

let path = match path {
Expand All @@ -75,25 +79,47 @@ pub fn run_command_override_set(
}
.canonicalize()?;

if config_file
if let Some(i) = config_file
.data
.overrides
.iter()
.any(|i| i.path == path.to_string_lossy())
.iter_mut()
.find(|i| i.path == path.to_string_lossy())
{
bail!(
"'{}' path already has an override configured.",
path.to_string_lossy()
);
if i.channel == channel {
eprintln!(
"Override already set to '{}' for '{}'.",
channel,
path.to_string_lossy()
);
return Ok(());
} else {
eprintln!(
"Override changed from '{}' to '{}' for '{}'.",
i.channel,
channel,
path.to_string_lossy()
);
i.channel = channel.clone();

save_config_db(&mut config_file).with_context(|| {
"Failed to save configuration file from `override set` command."
})?;
return Ok(());
}
}

config_file.data.overrides.push(JuliaupOverride {
path: path.to_string_lossy().to_string(),
channel: channel.clone(),
});
eprintln!(
"Override set to '{}' for '{}'.",
channel,
path.to_string_lossy()
);

save_config_db(&mut config_file)
.with_context(|| "Failed to save configuration file from `override add` command.")?;
.with_context(|| "Failed to save configuration file from `override set` command.")?;

Ok(())
}
Expand Down
31 changes: 30 additions & 1 deletion tests/command_override_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use assert_cmd::Command;
use predicates::prelude::PredicateBooleanExt;
use predicates::str::starts_with;

#[test]
fn command_override_status_test() {
Expand Down Expand Up @@ -83,6 +84,32 @@ fn command_override_cur_dir_test() {
.success()
.stdout("1.6.7");

Command::cargo_bin("juliaup")
.unwrap()
.arg("override")
.arg("set")
.arg("1.6.7")
.env("JULIA_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.current_dir(&or_dir)
.assert()
.success()
.stdout("")
.stderr(starts_with("Override set to '1.6.7'"));

Command::cargo_bin("juliaup")
.unwrap()
.arg("override")
.arg("set")
.arg("1.6.7")
.env("JULIA_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.current_dir(&or_dir)
.assert()
.success()
.stdout("")
.stderr(starts_with("Override already set to '1.6.7'"));

Command::cargo_bin("juliaup")
.unwrap()
.arg("override")
Expand All @@ -92,7 +119,9 @@ fn command_override_cur_dir_test() {
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.current_dir(&or_dir)
.assert()
.success();
.success()
.stdout("")
.stderr(starts_with("Override changed from '1.6.7' to '1.8.5'"));

Command::cargo_bin("julia")
.unwrap()
Expand Down