From 8c08f0128179ea768578da96c79f95d53b899d11 Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:24:57 -0300 Subject: [PATCH] Get current juliaup channel with `juliaup self channel` --- src/cli.rs | 5 ++--- src/command_selfchannel.rs | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) 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(()) }