From 39882c6d5339e9f98ceb6ed776632bcffd4fdf28 Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:47:15 -0300 Subject: [PATCH] Get current juliaup channel with `juliaup self channel` --- src/bin/juliainstaller.rs | 2 +- src/cli.rs | 5 ++--- src/command_selfchannel.rs | 19 ++++++++++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/bin/juliainstaller.rs b/src/bin/juliainstaller.rs index 16d3a68c..55db76fa 100644 --- a/src/bin/juliainstaller.rs +++ b/src/bin/juliainstaller.rs @@ -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`.")?; diff --git a/src/cli.rs b/src/cli.rs index 14588c55..1028a854 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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, }, #[cfg(feature = "selfupdate")] /// Uninstall this version of juliaup from the system diff --git a/src/command_selfchannel.rs b/src/command_selfchannel.rs index 79d29611..b7da7617 100644 --- a/src/command_selfchannel.rs +++ b/src/command_selfchannel.rs @@ -3,7 +3,7 @@ use anyhow::Result; #[cfg(feature = "selfupdate")] pub fn run_command_selfchannel( - channel: crate::cli::JuliaupChannel, + channel: Option, paths: &crate::global_paths::GlobalPaths, ) -> Result<()> { use crate::config_file::{load_mut_config_db, save_config_db}; @@ -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(()) }