Skip to content

Commit

Permalink
Merge pull request #882 from Gambitier/fix-819
Browse files Browse the repository at this point in the history
feat(juliaup): Improve error message for juliaup self channel
  • Loading branch information
davidanthoff authored Apr 30, 2024
2 parents 432626f + 5347b44 commit 4096719
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/bin/juliainstaller.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use clap::builder::BoolishValueParser;
use clap::Parser;
use juliaup::cli::JuliaupChannel;

#[cfg(feature = "selfupdate")]
fn run_individual_config_wizard(
Expand Down Expand Up @@ -120,8 +121,8 @@ struct Juliainstaller {
#[clap(long, default_value = "release")]
default_channel: String,
/// Juliaup channel
#[clap(long, default_value = "release")]
juliaup_channel: String,
#[clap(long, value_enum, default_value = "release")]
juliaup_channel: JuliaupChannel,
/// Disable confirmation prompt
#[clap(short = 'y', long = "yes")]
disable_confirmation_prompt: bool,
Expand Down
30 changes: 27 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::Parser;
use clap::{Parser, ValueEnum};

#[derive(Parser)]
#[clap(name = "Juliaup", version)]
Expand Down Expand Up @@ -73,6 +73,26 @@ pub enum OverrideSubCmd {
},
}

#[derive(Debug, ValueEnum, Clone)]
pub enum JuliaupChannel {
#[clap(name = "release")]
Release,
#[clap(name = "releasepreview")]
ReleasePreview,
#[clap(name = "dev")]
Dev,
}

impl JuliaupChannel {
pub fn to_lowercase(&self) -> &str {
match self {
JuliaupChannel::Release => "release",
JuliaupChannel::ReleasePreview => "releasepreview",
JuliaupChannel::Dev => "dev",
}
}
}

#[derive(Parser)]
/// Manage this juliaup installation
pub enum SelfSubCmd {
Expand All @@ -83,8 +103,12 @@ pub enum SelfSubCmd {
/// Update the Julia versions database and juliaup itself
Update {},
#[cfg(feature = "selfupdate")]
/// Configure the channel to use for juliaup updates
Channel { channel: String },
#[command(arg_required_else_help = true)]
/// Configure the channel to use for juliaup updates.
Channel {
#[arg(value_enum)]
channel: JuliaupChannel,
},
#[cfg(feature = "selfupdate")]
/// Uninstall this version of juliaup from the system
Uninstall {},
Expand Down
10 changes: 3 additions & 7 deletions src/command_selfchannel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ use anyhow::Result;

#[cfg(feature = "selfupdate")]
pub fn run_command_selfchannel(
channel: String,
channel: crate::cli::JuliaupChannel,
paths: &crate::global_paths::GlobalPaths,
) -> Result<()> {
use crate::config_file::{load_mut_config_db, save_config_db};
use anyhow::{bail, Context};
use anyhow::Context;

let mut config_file = load_mut_config_db(paths)
.with_context(|| "`self update` command failed to load configuration data.")?;

if channel != "dev" && channel != "releasepreview" && channel != "release" {
bail!("'{}' is not a valid juliaup channel, you can only specify 'release', 'releasepreview' or 'dev'.", channel);
}

config_file.self_data.juliaup_channel = Some(channel.clone());
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.")?;
Expand Down

0 comments on commit 4096719

Please sign in to comment.