Skip to content

Commit

Permalink
feat: return version info on success
Browse files Browse the repository at this point in the history
Returns old and new version info, plus the tag the new verson was built from.

Fixes #33.
  • Loading branch information
mistydemeo committed Mar 7, 2024
1 parent 9fb7747 commit 3578543
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions axoupdater-cli/src/bin/axoupdater/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ struct CliArgs {}
fn real_main(_cli: &CliApp<CliArgs>) -> Result<(), miette::Report> {
eprintln!("Checking for updates...");

if AxoUpdater::new_for_updater_executable()?
if let Some(result) = AxoUpdater::new_for_updater_executable()?
.load_receipt()?
.run_sync()?
{
eprintln!("New release installed!")
eprintln!("New release {} installed!", result.new_version)
} else {
eprintln!("Already up to date; not upgrading");
}
Expand Down
27 changes: 23 additions & 4 deletions axoupdater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ use serde::Deserialize;
use temp_dir::TempDir;
use thiserror::Error;

/// Provides information about the result of the upgrade operation
pub struct UpdateResult {
/// The old version (pre-upgrade)
pub old_version: String,
/// The new version (post-upgrade)
pub new_version: String,
/// The tag the new version was created from
pub new_version_tag: String,
}

/// Struct representing an updater process
pub struct AxoUpdater {
/// The name of the program to update, if specified
Expand Down Expand Up @@ -152,9 +162,9 @@ impl AxoUpdater {
/// update was actually performed or not; false indicates "no update was
/// needed", while an error indicates that an update couldn't be performed
/// due to an error.
pub async fn run(&mut self) -> AxoupdateResult<bool> {
pub async fn run(&mut self) -> AxoupdateResult<Option<UpdateResult>> {
if !self.is_update_needed().await? {
return Ok(false);
return Ok(None);
}

let release = match &self.latest_release {
Expand Down Expand Up @@ -218,12 +228,21 @@ impl AxoUpdater {
}
command.run()?;

Ok(true)
let result = UpdateResult {
old_version: self
.current_version
.to_owned()
.unwrap_or("unable to determine".to_owned()),
new_version: release.version(),
new_version_tag: release.tag_name.to_owned(),
};

Ok(Some(result))
}

#[cfg(feature = "blocking")]
/// Identical to Axoupdater::run(), but performed synchronously.
pub fn run_sync(&mut self) -> AxoupdateResult<bool> {
pub fn run_sync(&mut self) -> AxoupdateResult<Option<UpdateResult>> {
tokio::runtime::Builder::new_current_thread()
.worker_threads(1)
.max_blocking_threads(128)
Expand Down

0 comments on commit 3578543

Please sign in to comment.