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: allow disabling installer's output #37

Merged
merged 1 commit into from
Mar 7, 2024
Merged
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
61 changes: 61 additions & 0 deletions axoupdater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::{
env::{self, args, current_dir},
path::PathBuf,
process::Stdio,
};

#[cfg(unix)]
Expand Down Expand Up @@ -45,6 +46,10 @@ pub struct AxoUpdater {
latest_release: Option<Release>,
/// The current version number
current_version: Option<String>,
/// Whether to display the underlying installer's stdout
print_installer_stdout: bool,
/// Whether to display the underlying installer's stderr
print_installer_stderr: bool,
}

impl Default for AxoUpdater {
Expand All @@ -63,6 +68,8 @@ impl AxoUpdater {
source: None,
latest_release: None,
current_version: None,
print_installer_stdout: true,
print_installer_stderr: true,
}
}

Expand All @@ -73,6 +80,8 @@ impl AxoUpdater {
source: None,
latest_release: None,
current_version: None,
print_installer_stdout: true,
print_installer_stderr: true,
}
}

Expand All @@ -94,6 +103,8 @@ impl AxoUpdater {
source: None,
latest_release: None,
current_version: None,
print_installer_stdout: true,
print_installer_stderr: true,
})
}

Expand Down Expand Up @@ -122,6 +133,50 @@ impl AxoUpdater {
Ok(self)
}

/// Enables printing the underlying installer's stdout.
pub fn enable_installer_stdout(&mut self) -> &mut AxoUpdater {
self.print_installer_stdout = true;

self
}

/// Disables printing the underlying installer's stdout.
pub fn disable_installer_stdout(&mut self) -> &mut AxoUpdater {
self.print_installer_stdout = false;

self
}

/// Enables printing the underlying installer's stderr.
pub fn enable_installer_stderr(&mut self) -> &mut AxoUpdater {
self.print_installer_stderr = true;

self
}

/// Disables printing the underlying installer's stderr.
pub fn disable_installer_stderr(&mut self) -> &mut AxoUpdater {
self.print_installer_stderr = false;

self
}

/// Enables all output for the underlying installer.
pub fn enable_installer_output(&mut self) -> &mut AxoUpdater {
self.print_installer_stdout = true;
self.print_installer_stderr = true;

self
}

/// Disables all output for the underlying installer.
pub fn disable_installer_output(&mut self) -> &mut AxoUpdater {
self.print_installer_stdout = false;
self.print_installer_stderr = false;

self
}

/// Determines if an update is needed by querying the newest version from
/// the location specified in `source`.
/// This includes a blocking network call, so it may be slow.
Expand Down Expand Up @@ -226,6 +281,12 @@ impl AxoUpdater {
if cfg!(windows) {
command.arg(&installer_path);
}
if !self.print_installer_stdout {
command.stdout(Stdio::null());
}
if !self.print_installer_stderr {
command.stderr(Stdio::null());
}
command.run()?;

let result = UpdateResult {
Expand Down
Loading