Skip to content

Commit 133b97a

Browse files
authored
Fixes for alias feature (#1242)
1 parent 5546829 commit 133b97a

File tree

8 files changed

+214
-207
lines changed

8 files changed

+214
-207
lines changed

src/bin/julialauncher.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,6 @@ enum JuliaupChannelSource {
325325
Default,
326326
}
327327

328-
fn resolve_channel_alias(config_data: &JuliaupConfig, channel: &str) -> Result<String> {
329-
match config_data.installed_channels.get(channel) {
330-
Some(JuliaupConfigChannel::AliasChannel { target, args: _ }) => Ok(target.to_string()),
331-
_ => Ok(channel.to_string()),
332-
}
333-
}
334-
335328
fn get_julia_path_from_channel(
336329
versions_db: &JuliaupVersionDB,
337330
config_data: &JuliaupConfig,
@@ -340,8 +333,13 @@ fn get_julia_path_from_channel(
340333
juliaup_channel_source: JuliaupChannelSource,
341334
paths: &juliaup::global_paths::GlobalPaths,
342335
) -> Result<(PathBuf, Vec<String>)> {
343-
// First resolve any aliases
344-
let resolved_channel = resolve_channel_alias(config_data, channel)?;
336+
// First check if the channel is an alias and extract its args
337+
let (resolved_channel, alias_args) = match config_data.installed_channels.get(channel) {
338+
Some(JuliaupConfigChannel::AliasChannel { target, args }) => {
339+
(target.to_string(), args.clone().unwrap_or_default())
340+
}
341+
_ => (channel.to_string(), Vec::new()),
342+
};
345343

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

@@ -353,6 +351,7 @@ fn get_julia_path_from_channel(
353351
&resolved_channel,
354352
juliaupconfig_path,
355353
channel_info,
354+
alias_args.clone(),
356355
);
357356
}
358357

@@ -393,6 +392,7 @@ fn get_julia_path_from_channel(
393392
&resolved_channel,
394393
juliaupconfig_path,
395394
channel_info,
395+
alias_args,
396396
);
397397
} else {
398398
return Err(anyhow!(
@@ -445,15 +445,17 @@ fn get_julia_path_from_installed_channel(
445445
channel: &str,
446446
juliaupconfig_path: &Path,
447447
channel_info: &JuliaupConfigChannel,
448+
alias_args: Vec<String>,
448449
) -> Result<(PathBuf, Vec<String>)> {
449450
match channel_info {
450451
JuliaupConfigChannel::AliasChannel { .. } => {
451452
bail!("Unexpected alias channel after resolution: {channel}");
452453
}
453-
JuliaupConfigChannel::LinkedChannel { command, args } => Ok((
454-
PathBuf::from(command),
455-
args.as_ref().map_or_else(Vec::new, |v| v.clone()),
456-
)),
454+
JuliaupConfigChannel::LinkedChannel { command, args } => {
455+
let mut combined_args = alias_args;
456+
combined_args.extend(args.as_ref().map_or_else(Vec::new, |v| v.clone()));
457+
Ok((PathBuf::from(command), combined_args))
458+
}
457459
JuliaupConfigChannel::SystemChannel { version } => {
458460
let path = &config_data
459461
.installed_versions.get(version)
@@ -475,7 +477,7 @@ fn get_julia_path_from_installed_channel(
475477
juliaupconfig_path.display()
476478
)
477479
})?;
478-
Ok((absolute_path.into_path_buf(), Vec::new()))
480+
Ok((absolute_path.into_path_buf(), alias_args))
479481
}
480482
JuliaupConfigChannel::DirectDownloadChannel {
481483
path,
@@ -518,7 +520,7 @@ fn get_julia_path_from_installed_channel(
518520
juliaupconfig_path.display()
519521
)
520522
})?;
521-
Ok((absolute_path.into_path_buf(), Vec::new()))
523+
Ok((absolute_path.into_path_buf(), alias_args))
522524
}
523525
}
524526
}

src/command_api.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,21 @@ pub fn run_command_api(command: &str, paths: &GlobalPaths) -> Result<()> {
4545

4646
for (key, value) in &config_file.data.installed_channels {
4747
let curr = match &value {
48-
JuliaupConfigChannel::AliasChannel { target, args: _ } => {
48+
JuliaupConfigChannel::DirectDownloadChannel { path, url: _, local_etag: _, server_etag: _, version } => {
4949
JuliaupChannelInfo {
5050
name: key.clone(),
51-
file: format!("alias-to-{target}"),
51+
file: paths.juliauphome
52+
.join(path)
53+
.join("bin")
54+
.join(format!("julia{}", std::env::consts::EXE_SUFFIX))
55+
.normalize()
56+
.with_context(|| "Normalizing the path for an entry from the config file failed while running the getconfig1 API command.")?
57+
.into_path_buf()
58+
.to_string_lossy()
59+
.to_string(),
5260
args: Vec::new(),
53-
version: format!("alias to {target}"),
54-
arch: String::new(),
61+
version: version.clone(),
62+
arch: "".to_string(),
5563
}
5664
}
5765
JuliaupConfigChannel::SystemChannel { version: fullversion } => {
@@ -111,21 +119,13 @@ pub fn run_command_api(command: &str, paths: &GlobalPaths) -> Result<()> {
111119
Err(_) => continue,
112120
}
113121
}
114-
JuliaupConfigChannel::DirectDownloadChannel { path, url: _, local_etag: _, server_etag: _, version } => {
122+
JuliaupConfigChannel::AliasChannel { target, args } => {
115123
JuliaupChannelInfo {
116124
name: key.clone(),
117-
file: paths.juliauphome
118-
.join(path)
119-
.join("bin")
120-
.join(format!("julia{}", std::env::consts::EXE_SUFFIX))
121-
.normalize()
122-
.with_context(|| "Normalizing the path for an entry from the config file failed while running the getconfig1 API command.")?
123-
.into_path_buf()
124-
.to_string_lossy()
125-
.to_string(),
126-
args: Vec::new(),
127-
version: version.clone(),
128-
arch: "".to_string(),
125+
file: format!("alias-to-{target}"),
126+
args: args.clone().unwrap_or_default(),
127+
version: format!("alias to {target}"),
128+
arch: String::new(),
129129
}
130130
}
131131
};

src/command_remove.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ pub fn run_command_remove(channel: &str, paths: &GlobalPaths) -> Result<()> {
4343

4444
// Determine what type of channel is being removed for better messaging
4545
let channel_type = match channel_info {
46-
JuliaupConfigChannel::AliasChannel { target, args: _ } => {
46+
JuliaupConfigChannel::DirectDownloadChannel { .. } => "channel".to_string(),
47+
JuliaupConfigChannel::SystemChannel { .. } => "channel".to_string(),
48+
JuliaupConfigChannel::LinkedChannel { .. } => "linked channel".to_string(),
49+
JuliaupConfigChannel::AliasChannel { target, .. } => {
4750
format!("alias (pointing to '{target}')")
4851
}
49-
JuliaupConfigChannel::LinkedChannel { .. } => "linked channel".to_string(),
50-
JuliaupConfigChannel::SystemChannel { .. } => "channel".to_string(),
51-
JuliaupConfigChannel::DirectDownloadChannel { .. } => "channel".to_string(),
5252
};
5353

5454
if let JuliaupConfigChannel::DirectDownloadChannel {

src/command_status.rs

Lines changed: 89 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,93 @@ use cli_table::{
1414
use itertools::Itertools;
1515
use numeric_sort::cmp;
1616

17-
fn get_alias_update_info(
18-
target: &str,
17+
fn format_linked_command(command: &str, args: &Option<Vec<String>>) -> String {
18+
let mut combined_command = String::new();
19+
20+
if command.contains(' ') {
21+
combined_command.push('\"');
22+
combined_command.push_str(command);
23+
combined_command.push('\"');
24+
} else {
25+
combined_command.push_str(command);
26+
}
27+
28+
if let Some(args) = args {
29+
for arg in args {
30+
combined_command.push(' ');
31+
if arg.contains(' ') {
32+
combined_command.push('\"');
33+
combined_command.push_str(arg);
34+
combined_command.push('\"');
35+
} else {
36+
combined_command.push_str(arg);
37+
}
38+
}
39+
}
40+
41+
format!("Linked to `{combined_command}`")
42+
}
43+
44+
fn format_version(channel: &JuliaupConfigChannel) -> String {
45+
match channel {
46+
JuliaupConfigChannel::DirectDownloadChannel { version, .. } => {
47+
format!("Development version {version}")
48+
}
49+
JuliaupConfigChannel::SystemChannel { version } => version.clone(),
50+
JuliaupConfigChannel::LinkedChannel { command, args } => {
51+
format_linked_command(command, args)
52+
}
53+
JuliaupConfigChannel::AliasChannel { target, args } => match args {
54+
Some(args) if !args.is_empty() => {
55+
format!("Alias to `{target}` with args: {:?}", args)
56+
}
57+
_ => format!("Alias to `{target}`"),
58+
},
59+
}
60+
}
61+
62+
fn get_update_info(
63+
channel_name: &str,
64+
channel: &JuliaupConfigChannel,
1965
config_file: &JuliaupReadonlyConfigFile,
2066
versiondb_data: &JuliaupVersionDB,
21-
) -> Option<String> {
22-
// Check if the target channel has updates available
23-
match config_file.data.installed_channels.get(target) {
24-
Some(JuliaupConfigChannel::SystemChannel { version }) => {
25-
match versiondb_data.available_channels.get(target) {
26-
Some(channel) if channel.version != *version => {
67+
) -> String {
68+
match channel {
69+
JuliaupConfigChannel::DirectDownloadChannel {
70+
local_etag,
71+
server_etag,
72+
..
73+
} => (local_etag != server_etag).then(|| "Update available".to_string()),
74+
JuliaupConfigChannel::SystemChannel { version } => {
75+
match versiondb_data.available_channels.get(channel_name) {
76+
Some(channel) if &channel.version != version => {
2777
Some(format!("Update to {} available", channel.version))
2878
}
2979
_ => None,
3080
}
3181
}
32-
Some(JuliaupConfigChannel::DirectDownloadChannel {
33-
local_etag,
34-
server_etag,
35-
..
36-
}) => (local_etag != server_etag).then(|| "Update available".to_string()),
37-
_ => None, // Target channel doesn't exist or not updatable
82+
JuliaupConfigChannel::LinkedChannel { .. } => None,
83+
JuliaupConfigChannel::AliasChannel { target, .. } => {
84+
// Check if the target channel has updates available
85+
match config_file.data.installed_channels.get(target) {
86+
Some(JuliaupConfigChannel::DirectDownloadChannel {
87+
local_etag,
88+
server_etag,
89+
..
90+
}) => (local_etag != server_etag).then(|| "Update available".to_string()),
91+
Some(JuliaupConfigChannel::SystemChannel { version }) => {
92+
match versiondb_data.available_channels.get(target) {
93+
Some(channel) if channel.version != *version => {
94+
Some(format!("Update to {} available", channel.version))
95+
}
96+
_ => None,
97+
}
98+
}
99+
_ => None, // Target channel doesn't exist or not updatable
100+
}
101+
}
38102
}
103+
.unwrap_or_default()
39104
}
40105

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

60-
let rows_in_table: Vec<_> = config_file
125+
let rows_in_table: Vec<ChannelRow> = config_file
61126
.data
62127
.installed_channels
63128
.iter()
64-
.sorted_by(|a, b| cmp(&a.0.to_string(), &b.0.to_string()))
65-
.map(|i| -> ChannelRow {
66-
ChannelRow {
67-
default: match config_file.data.default {
68-
Some(ref default_value) => {
69-
if i.0 == default_value {
70-
"*"
71-
} else {
72-
""
73-
}
74-
}
75-
None => "",
76-
},
77-
name: i.0.to_string(),
78-
version: match i.1 {
79-
JuliaupConfigChannel::SystemChannel { version } => version.clone(),
80-
JuliaupConfigChannel::DirectDownloadChannel {
81-
path: _,
82-
url: _,
83-
local_etag: _,
84-
server_etag: _,
85-
version,
86-
} => {
87-
format!("Development version {version}")
88-
}
89-
JuliaupConfigChannel::LinkedChannel { command, args } => {
90-
let mut combined_command = String::new();
91-
92-
if command.contains(' ') {
93-
combined_command.push('\"');
94-
combined_command.push_str(command);
95-
combined_command.push('\"');
96-
} else {
97-
combined_command.push_str(command);
98-
}
99-
100-
if let Some(args) = args {
101-
for i in args {
102-
combined_command.push(' ');
103-
if i.contains(' ') {
104-
combined_command.push('\"');
105-
combined_command.push_str(i);
106-
combined_command.push('\"');
107-
} else {
108-
combined_command.push_str(i);
109-
}
110-
}
111-
}
112-
format!("Linked to `{combined_command}`")
113-
}
114-
JuliaupConfigChannel::AliasChannel { target, args } => match args {
115-
Some(args) if !args.is_empty() => {
116-
format!("Alias to `{target}` with args: {:?}", args)
117-
}
118-
_ => format!("Alias to `{target}`"),
119-
},
120-
},
121-
update: {
122-
let update_option = match i.1 {
123-
JuliaupConfigChannel::SystemChannel { version } => {
124-
match versiondb_data.available_channels.get(i.0) {
125-
Some(channel) if &channel.version != version => {
126-
Some(format!("Update to {} available", channel.version))
127-
}
128-
_ => None,
129-
}
130-
}
131-
JuliaupConfigChannel::LinkedChannel { .. } => None,
132-
JuliaupConfigChannel::AliasChannel { target, args: _ } => {
133-
get_alias_update_info(target, &config_file, &versiondb_data)
134-
}
135-
JuliaupConfigChannel::DirectDownloadChannel {
136-
local_etag,
137-
server_etag,
138-
..
139-
} => (local_etag != server_etag).then(|| "Update available".to_string()),
140-
};
141-
update_option.unwrap_or_default()
142-
},
143-
}
129+
.sorted_by(|(channel_name_a, _), (channel_name_b, _)| cmp(channel_name_a, channel_name_b))
130+
.map(|(channel_name, channel)| ChannelRow {
131+
default: match &config_file.data.default {
132+
Some(ref default_value) if channel_name == default_value => "*",
133+
_ => "",
134+
},
135+
name: channel_name.to_string(),
136+
version: format_version(channel),
137+
update: get_update_info(channel_name, channel, &config_file, &versiondb_data),
144138
})
145139
.collect();
146140

0 commit comments

Comments
 (0)