Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(juliaup): Improve error message for juliaup self channel #882

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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