Skip to content

Commit

Permalink
Get current juliaup channel with juliaup self channel
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Sep 3, 2024
1 parent f160605 commit 39882c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/bin/juliainstaller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ pub fn main() -> Result<()> {
run_command_config_modifypath(Some(install_choices.modifypath), true, &paths).unwrap();
}
run_command_config_symlinks(Some(install_choices.symlinks), true, &paths).unwrap();
run_command_selfchannel(args.juliaup_channel, &paths).unwrap();
run_command_selfchannel(Some(args.juliaup_channel), &paths).unwrap();

run_command_add(&args.default_channel, &paths)
.with_context(|| "Failed to run `run_command_add`.")?;
Expand Down
5 changes: 2 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ pub enum SelfSubCmd {
/// Update the Julia versions database and juliaup itself
Update {},
#[cfg(feature = "selfupdate")]
#[command(arg_required_else_help = true)]
/// Configure the channel to use for juliaup updates.
/// Configure the channel to use for juliaup updates. Leave CHANNEL blank to see current channel.
Channel {
#[arg(value_enum)]
channel: JuliaupChannel,
channel: Option<JuliaupChannel>,
},
#[cfg(feature = "selfupdate")]
/// Uninstall this version of juliaup from the system
Expand Down
19 changes: 14 additions & 5 deletions src/command_selfchannel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::Result;

#[cfg(feature = "selfupdate")]
pub fn run_command_selfchannel(
channel: crate::cli::JuliaupChannel,
channel: Option<crate::cli::JuliaupChannel>,
paths: &crate::global_paths::GlobalPaths,
) -> Result<()> {
use crate::config_file::{load_mut_config_db, save_config_db};
Expand All @@ -12,10 +12,19 @@ pub fn run_command_selfchannel(
let mut config_file = load_mut_config_db(paths)
.with_context(|| "`self update` command failed to load configuration data.")?;

config_file.self_data.juliaup_channel = Some(channel.to_lowercase().to_string());

save_config_db(&mut config_file)
.with_context(|| "`selfchannel` command failed to save configuration db.")?;
match channel {
Some(chan) => {
config_file.self_data.juliaup_channel = Some(chan.to_lowercase().to_string());
save_config_db(&mut config_file)?;
}
None => {
let channel_name = config_file
.self_data
.juliaup_channel
.expect("juliaup_channel should not be empty.");
println!("Your juliaup is currently on channel `{}`. Run `juliaup self channel -h` for help on how to set the juliaup channel.", channel_name);
}
}

Ok(())
}

0 comments on commit 39882c6

Please sign in to comment.