Skip to content
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
32 changes: 17 additions & 15 deletions src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,6 @@ enum JuliaupChannelSource {
Default,
}

fn resolve_channel_alias(config_data: &JuliaupConfig, channel: &str) -> Result<String> {
match config_data.installed_channels.get(channel) {
Some(JuliaupConfigChannel::AliasChannel { target, args: _ }) => Ok(target.to_string()),
_ => Ok(channel.to_string()),
}
}

fn get_julia_path_from_channel(
versions_db: &JuliaupVersionDB,
config_data: &JuliaupConfig,
Expand All @@ -340,8 +333,13 @@ fn get_julia_path_from_channel(
juliaup_channel_source: JuliaupChannelSource,
paths: &juliaup::global_paths::GlobalPaths,
) -> Result<(PathBuf, Vec<String>)> {
// First resolve any aliases
let resolved_channel = resolve_channel_alias(config_data, channel)?;
// First check if the channel is an alias and extract its args
let (resolved_channel, alias_args) = match config_data.installed_channels.get(channel) {
Some(JuliaupConfigChannel::AliasChannel { target, args }) => {
(target.to_string(), args.clone().unwrap_or_default())
}
_ => (channel.to_string(), Vec::new()),
};

let channel_valid = is_valid_channel(versions_db, &resolved_channel)?;

Expand All @@ -353,6 +351,7 @@ fn get_julia_path_from_channel(
&resolved_channel,
juliaupconfig_path,
channel_info,
alias_args.clone(),
);
}

Expand Down Expand Up @@ -393,6 +392,7 @@ fn get_julia_path_from_channel(
&resolved_channel,
juliaupconfig_path,
channel_info,
alias_args,
);
} else {
return Err(anyhow!(
Expand Down Expand Up @@ -445,15 +445,17 @@ fn get_julia_path_from_installed_channel(
channel: &str,
juliaupconfig_path: &Path,
channel_info: &JuliaupConfigChannel,
alias_args: Vec<String>,
) -> Result<(PathBuf, Vec<String>)> {
match channel_info {
JuliaupConfigChannel::AliasChannel { .. } => {
bail!("Unexpected alias channel after resolution: {channel}");
}
JuliaupConfigChannel::LinkedChannel { command, args } => Ok((
PathBuf::from(command),
args.as_ref().map_or_else(Vec::new, |v| v.clone()),
)),
JuliaupConfigChannel::LinkedChannel { command, args } => {
let mut combined_args = alias_args;
combined_args.extend(args.as_ref().map_or_else(Vec::new, |v| v.clone()));
Ok((PathBuf::from(command), combined_args))
}
JuliaupConfigChannel::SystemChannel { version } => {
let path = &config_data
.installed_versions.get(version)
Expand All @@ -475,7 +477,7 @@ fn get_julia_path_from_installed_channel(
juliaupconfig_path.display()
)
})?;
Ok((absolute_path.into_path_buf(), Vec::new()))
Ok((absolute_path.into_path_buf(), alias_args))
}
JuliaupConfigChannel::DirectDownloadChannel {
path,
Expand Down Expand Up @@ -518,7 +520,7 @@ fn get_julia_path_from_installed_channel(
juliaupconfig_path.display()
)
})?;
Ok((absolute_path.into_path_buf(), Vec::new()))
Ok((absolute_path.into_path_buf(), alias_args))
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/command_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ pub fn run_command_api(command: &str, paths: &GlobalPaths) -> Result<()> {

for (key, value) in &config_file.data.installed_channels {
let curr = match &value {
JuliaupConfigChannel::AliasChannel { target, args: _ } => {
JuliaupConfigChannel::DirectDownloadChannel { path, url: _, local_etag: _, server_etag: _, version } => {
JuliaupChannelInfo {
name: key.clone(),
file: format!("alias-to-{target}"),
file: paths.juliauphome
.join(path)
.join("bin")
.join(format!("julia{}", std::env::consts::EXE_SUFFIX))
.normalize()
.with_context(|| "Normalizing the path for an entry from the config file failed while running the getconfig1 API command.")?
.into_path_buf()
.to_string_lossy()
.to_string(),
args: Vec::new(),
version: format!("alias to {target}"),
arch: String::new(),
version: version.clone(),
arch: "".to_string(),
}
}
JuliaupConfigChannel::SystemChannel { version: fullversion } => {
Expand Down Expand Up @@ -111,21 +119,13 @@ pub fn run_command_api(command: &str, paths: &GlobalPaths) -> Result<()> {
Err(_) => continue,
}
}
JuliaupConfigChannel::DirectDownloadChannel { path, url: _, local_etag: _, server_etag: _, version } => {
JuliaupConfigChannel::AliasChannel { target, args } => {
JuliaupChannelInfo {
name: key.clone(),
file: paths.juliauphome
.join(path)
.join("bin")
.join(format!("julia{}", std::env::consts::EXE_SUFFIX))
.normalize()
.with_context(|| "Normalizing the path for an entry from the config file failed while running the getconfig1 API command.")?
.into_path_buf()
.to_string_lossy()
.to_string(),
args: Vec::new(),
version: version.clone(),
arch: "".to_string(),
file: format!("alias-to-{target}"),
args: args.clone().unwrap_or_default(),
version: format!("alias to {target}"),
arch: String::new(),
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/command_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ pub fn run_command_remove(channel: &str, paths: &GlobalPaths) -> Result<()> {

// Determine what type of channel is being removed for better messaging
let channel_type = match channel_info {
JuliaupConfigChannel::AliasChannel { target, args: _ } => {
JuliaupConfigChannel::DirectDownloadChannel { .. } => "channel".to_string(),
JuliaupConfigChannel::SystemChannel { .. } => "channel".to_string(),
JuliaupConfigChannel::LinkedChannel { .. } => "linked channel".to_string(),
JuliaupConfigChannel::AliasChannel { target, .. } => {
format!("alias (pointing to '{target}')")
}
JuliaupConfigChannel::LinkedChannel { .. } => "linked channel".to_string(),
JuliaupConfigChannel::SystemChannel { .. } => "channel".to_string(),
JuliaupConfigChannel::DirectDownloadChannel { .. } => "channel".to_string(),
};

if let JuliaupConfigChannel::DirectDownloadChannel {
Expand Down
184 changes: 89 additions & 95 deletions src/command_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,93 @@ use cli_table::{
use itertools::Itertools;
use numeric_sort::cmp;

fn get_alias_update_info(
target: &str,
fn format_linked_command(command: &str, args: &Option<Vec<String>>) -> String {
let mut combined_command = String::new();

if command.contains(' ') {
combined_command.push('\"');
combined_command.push_str(command);
combined_command.push('\"');
} else {
combined_command.push_str(command);
}

if let Some(args) = args {
for arg in args {
combined_command.push(' ');
if arg.contains(' ') {
combined_command.push('\"');
combined_command.push_str(arg);
combined_command.push('\"');
} else {
combined_command.push_str(arg);
}
}
}

format!("Linked to `{combined_command}`")
}

fn format_version(channel: &JuliaupConfigChannel) -> String {
match channel {
JuliaupConfigChannel::DirectDownloadChannel { version, .. } => {
format!("Development version {version}")
}
JuliaupConfigChannel::SystemChannel { version } => version.clone(),
JuliaupConfigChannel::LinkedChannel { command, args } => {
format_linked_command(command, args)
}
JuliaupConfigChannel::AliasChannel { target, args } => match args {
Some(args) if !args.is_empty() => {
format!("Alias to `{target}` with args: {:?}", args)
}
_ => format!("Alias to `{target}`"),
},
}
}

fn get_update_info(
channel_name: &str,
channel: &JuliaupConfigChannel,
config_file: &JuliaupReadonlyConfigFile,
versiondb_data: &JuliaupVersionDB,
) -> Option<String> {
// Check if the target channel has updates available
match config_file.data.installed_channels.get(target) {
Some(JuliaupConfigChannel::SystemChannel { version }) => {
match versiondb_data.available_channels.get(target) {
Some(channel) if channel.version != *version => {
) -> String {
match channel {
JuliaupConfigChannel::DirectDownloadChannel {
local_etag,
server_etag,
..
} => (local_etag != server_etag).then(|| "Update available".to_string()),
JuliaupConfigChannel::SystemChannel { version } => {
match versiondb_data.available_channels.get(channel_name) {
Some(channel) if &channel.version != version => {
Some(format!("Update to {} available", channel.version))
}
_ => None,
}
}
Some(JuliaupConfigChannel::DirectDownloadChannel {
local_etag,
server_etag,
..
}) => (local_etag != server_etag).then(|| "Update available".to_string()),
_ => None, // Target channel doesn't exist or not updatable
JuliaupConfigChannel::LinkedChannel { .. } => None,
JuliaupConfigChannel::AliasChannel { target, .. } => {
// Check if the target channel has updates available
match config_file.data.installed_channels.get(target) {
Some(JuliaupConfigChannel::DirectDownloadChannel {
local_etag,
server_etag,
..
}) => (local_etag != server_etag).then(|| "Update available".to_string()),
Some(JuliaupConfigChannel::SystemChannel { version }) => {
match versiondb_data.available_channels.get(target) {
Some(channel) if channel.version != *version => {
Some(format!("Update to {} available", channel.version))
}
_ => None,
}
}
_ => None, // Target channel doesn't exist or not updatable
}
}
}
.unwrap_or_default()
}

#[derive(Table)]
Expand All @@ -57,90 +122,19 @@ pub fn run_command_status(paths: &GlobalPaths) -> Result<()> {
let versiondb_data =
load_versions_db(paths).with_context(|| "`status` command failed to load versions db.")?;

let rows_in_table: Vec<_> = config_file
let rows_in_table: Vec<ChannelRow> = config_file
.data
.installed_channels
.iter()
.sorted_by(|a, b| cmp(&a.0.to_string(), &b.0.to_string()))
.map(|i| -> ChannelRow {
ChannelRow {
default: match config_file.data.default {
Some(ref default_value) => {
if i.0 == default_value {
"*"
} else {
""
}
}
None => "",
},
name: i.0.to_string(),
version: match i.1 {
JuliaupConfigChannel::SystemChannel { version } => version.clone(),
JuliaupConfigChannel::DirectDownloadChannel {
path: _,
url: _,
local_etag: _,
server_etag: _,
version,
} => {
format!("Development version {version}")
}
JuliaupConfigChannel::LinkedChannel { command, args } => {
let mut combined_command = String::new();

if command.contains(' ') {
combined_command.push('\"');
combined_command.push_str(command);
combined_command.push('\"');
} else {
combined_command.push_str(command);
}

if let Some(args) = args {
for i in args {
combined_command.push(' ');
if i.contains(' ') {
combined_command.push('\"');
combined_command.push_str(i);
combined_command.push('\"');
} else {
combined_command.push_str(i);
}
}
}
format!("Linked to `{combined_command}`")
}
JuliaupConfigChannel::AliasChannel { target, args } => match args {
Some(args) if !args.is_empty() => {
format!("Alias to `{target}` with args: {:?}", args)
}
_ => format!("Alias to `{target}`"),
},
},
update: {
let update_option = match i.1 {
JuliaupConfigChannel::SystemChannel { version } => {
match versiondb_data.available_channels.get(i.0) {
Some(channel) if &channel.version != version => {
Some(format!("Update to {} available", channel.version))
}
_ => None,
}
}
JuliaupConfigChannel::LinkedChannel { .. } => None,
JuliaupConfigChannel::AliasChannel { target, args: _ } => {
get_alias_update_info(target, &config_file, &versiondb_data)
}
JuliaupConfigChannel::DirectDownloadChannel {
local_etag,
server_etag,
..
} => (local_etag != server_etag).then(|| "Update available".to_string()),
};
update_option.unwrap_or_default()
},
}
.sorted_by(|(channel_name_a, _), (channel_name_b, _)| cmp(channel_name_a, channel_name_b))
.map(|(channel_name, channel)| ChannelRow {
default: match &config_file.data.default {
Some(ref default_value) if channel_name == default_value => "*",
_ => "",
},
name: channel_name.to_string(),
version: format_version(channel),
update: get_update_info(channel_name, channel, &config_file, &versiondb_data),
})
.collect();

Expand Down
Loading
Loading