Skip to content

Commit

Permalink
Merge pull request #1002 from visr/override-override
Browse files Browse the repository at this point in the history
Support overriding an override
  • Loading branch information
davidanthoff authored Sep 6, 2024
2 parents af3b983 + 99d09b5 commit 1f45462
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
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

0 comments on commit 1f45462

Please sign in to comment.