Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Sep 6, 2024
1 parent ce2347c commit 89841a6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,26 +175,27 @@ fn get_julia_path_from_channel(
juliaupconfig_path: &Path,
juliaup_channel_source: JuliaupChannelSource,
) -> Result<(PathBuf, Vec<String>)> {
let channel_valid = is_valid_channel(versions_db, &channel.to_string())?;
let channel_info = config_data
.installed_channels
.get(channel)
.ok_or_else(|| match juliaup_channel_source {
JuliaupChannelSource::CmdLine => {
if is_valid_channel(versions_db, &channel.to_string()) {
if channel_valid {
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else {
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
JuliaupChannelSource::EnvVar=> {
if is_valid_channel(versions_db, &channel.to_string()) {
if channel_valid {
UserError { msg: format!("`{}` from environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else {
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` from environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
JuliaupChannelSource::Override=> {
if is_valid_channel(versions_db, &channel.to_string()) {
if channel_valid {
UserError { msg: format!("`{}` from directory override is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else {
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` from directory override. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
Expand Down
2 changes: 1 addition & 1 deletion src/command_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn run_command_default(channel: &str, paths: &GlobalPaths) -> Result<()> {
if !config_file.data.installed_channels.contains_key(channel) {
let version_db = load_versions_db(paths)
.with_context(|| "`default` command failed to load versions db.")?;
if !is_valid_channel(&version_db, &channel.to_string()) {
if !is_valid_channel(&version_db, &channel.to_string())? {
bail!("'{}' is not a valid Julia version.", channel);
} else {
bail!(
Expand Down
2 changes: 1 addition & 1 deletion src/command_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn run_command_link(
bail!("Channel name `{}` is already used.", channel)
}

if is_valid_channel(&versiondb_data, &channel.to_string()) {
if is_valid_channel(&versiondb_data, &channel.to_string())? {
eprintln!("WARNING: The channel name `{}` is also a system channel. By linking your custom binary to this channel you are hiding this system channel.", channel);
}

Expand Down
22 changes: 9 additions & 13 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,27 +434,23 @@ pub fn compatible_archs() -> Result<Vec<String>> {

// which nightly channels are compatible with the current system
fn compatible_nightly_channels() -> Result<Vec<String>> {
let archs: Result<Vec<String>> = compatible_archs();
let archs: Vec<String> = compatible_archs()?;

if archs.is_ok() {
let channels: Vec<String> = std::iter::once("nightly".to_string())
.chain(archs?.into_iter().map(|arch| format!("nightly~{}", arch)))
.collect();
Ok(channels)
} else {
archs
}
let channels: Vec<String> = std::iter::once("nightly".to_string())
.chain(archs.into_iter().map(|arch| format!("nightly~{}", arch)))
.collect();
Ok(channels)
}

// considers the nightly channels as system channels
// XXX: does not account for PR channels
pub fn is_valid_channel(versions_db: &JuliaupVersionDB, channel: &String) -> bool {
pub fn is_valid_channel(versions_db: &JuliaupVersionDB, channel: &String) -> Result<bool> {
let regular = versions_db.available_channels.contains_key(channel);

let nightly_chans = compatible_nightly_channels();
let nightly_chans = compatible_nightly_channels()?;

let nightly = nightly_chans.is_ok_and(|nightly_chans| nightly_chans.contains(channel));
regular || nightly
let nightly = nightly_chans.contains(channel);
Ok(regular || nightly)
}

// Identify the unversioned name of a nightly (e.g., `latest-macos-x86_64`) for a channel
Expand Down

0 comments on commit 89841a6

Please sign in to comment.