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 8c08f01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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 8c08f01

Please sign in to comment.