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: return version info on success #36

Merged
merged 1 commit into from
Mar 7, 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
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
Loading