Skip to content

Commit

Permalink
Merge pull request #234 from axodotdev/load-alt-receipts
Browse files Browse the repository at this point in the history
feat: allow loading alternate receipts
  • Loading branch information
mistydemeo authored Dec 18, 2024
2 parents 1d4bfc1 + 18bcd3e commit 4d12a39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions axoupdater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ impl AxoUpdater {
Ok(self)
}

/// Changes this updater's name to `app_name`, regardless of what it was
/// initialized as and regardless of what was read from the receipt.
pub fn set_name(&mut self, app_name: &str) -> &mut AxoUpdater {
self.name = Some(app_name.to_owned());
if let Some(source) = &self.source {
let mut our_source = source.clone();
our_source.app_name = app_name.to_owned();
self.source = Some(our_source);
}

self
}

/// Enables printing the underlying installer's stdout.
pub fn enable_installer_stdout(&mut self) -> &mut AxoUpdater {
self.print_installer_stdout = true;
Expand Down
10 changes: 9 additions & 1 deletion axoupdater/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ impl AxoUpdater {
/// Shell and Powershell installers produced by cargo-dist since 0.9.0
/// will have created an install receipt.
pub fn load_receipt(&mut self) -> AxoupdateResult<&mut AxoUpdater> {
let Some(app_name) = &self.name else {
let Some(app_name) = self.name.clone() else {
return Err(AxoupdateError::NoAppNamePassed {});
};

self.load_receipt_as(&app_name)
}

/// Similar to `AxoUpdater::load_receipt`, but loads a receipt for the app
/// with the name `app_name` instead of the auto-detected name. This can be
/// useful if the receipt may exist under several different names, for
/// example if an app has been renamed.
pub fn load_receipt_as(&mut self, app_name: &str) -> AxoupdateResult<&mut AxoUpdater> {
let receipt = load_receipt_for(app_name)?;

self.source = Some(receipt.source);
Expand Down

0 comments on commit 4d12a39

Please sign in to comment.