Skip to content

Commit

Permalink
Allow user to update all without using --all flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MordechaiHadad committed Jun 10, 2024
1 parent 5fb270c commit 7c2a237
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
8 changes: 2 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use clap::{Args, CommandFactory, Parser};
use clap_complete::Shell;
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};
use reqwest::{Client, Error};
use tracing::{error, info};
use tracing::info;

fn create_reqwest_client() -> Result<Client, Error> {
// fetch env variable
Expand Down Expand Up @@ -144,11 +144,7 @@ pub async fn start(config: Config) -> Result<()> {
clap_complete::generate(shell, &mut Cli::command(), "bob", &mut std::io::stdout())
}
Cli::Update(data) => {
if data.version.is_some() || data.all {
update_handler::start(data, &client, config).await?;
} else {
error!("Please provide a version or use the --all flag");
}
update_handler::start(data, &client, config).await?;
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/handlers/update_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@ use tracing::{info, warn};
use super::{install_handler, InstallResult};

pub async fn start(data: Update, client: &Client, config: Config) -> Result<()> {
if data.all {
if data.version.is_none() || data.all {
let mut did_update = false;

let mut stable = crate::version::parse_version_type(client, "stable").await?;
if is_version_installed(&stable.tag_name, &config).await? {
match install_handler::start(&mut stable, client, &config).await? {
InstallResult::VersionAlreadyInstalled => info!("Stable is already updated!"),
InstallResult::InstallationSuccess(_)
InstallResult::InstallationSuccess(_) => did_update = true,
InstallResult::VersionAlreadyInstalled
| InstallResult::NightlyIsUpdated
| InstallResult::GivenNightlyRollback => (),
}
did_update = true;
}

if is_version_installed("nightly", &config).await? {
let mut nightly = crate::version::parse_version_type(client, "nightly").await?;
match install_handler::start(&mut nightly, client, &config).await? {
InstallResult::NightlyIsUpdated => info!("Nightly is already updated!"),
InstallResult::InstallationSuccess(_)
InstallResult::InstallationSuccess(_) => did_update = true,
InstallResult::NightlyIsUpdated
| InstallResult::VersionAlreadyInstalled
| InstallResult::GivenNightlyRollback => (),
}

did_update = true;
}

if !did_update {
Expand Down

0 comments on commit 7c2a237

Please sign in to comment.