Skip to content

Commit

Permalink
refactor: pull the offline flag on a global level
Browse files Browse the repository at this point in the history
This will also skip the update check if the flag is enabled.

See #732
  • Loading branch information
ctron committed Oct 4, 2024
1 parent 7eb1d55 commit 81e6ab1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ pub struct Build {
#[arg(short, long, env = "TRUNK_BUILD_DIST")]
pub dist: Option<PathBuf>,

/// Run without accessing the network
#[arg(long, env = "TRUNK_BUILD_OFFLINE")]
#[arg(default_missing_value="true", num_args=0..=1)]
#[arg(from_global)]
pub offline: Option<bool>,

/// Require Cargo.lock and cache are up to date
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ struct Trunk {
#[arg(long, global(true), env = "TRUNK_SKIP_VERSION_CHECK")]
pub skip_version_check: bool,

/// Run without accessing the network
#[arg(long, global(true), env = "TRUNK_OFFLINE")]
#[arg(default_missing_value = "true", num_args=0..=1)]
pub offline: Option<bool>,

/// Color mode
#[arg(long, env = "TRUNK_COLOR", global(true), value_enum, conflicts_with = "no_color", default_value_t = ColorMode::Auto)]
pub color: ColorMode,
Expand Down Expand Up @@ -167,7 +172,7 @@ enum ColorMode {
impl Trunk {
#[tracing::instrument(level = "trace", skip(self))]
pub async fn run(self) -> Result<()> {
version::update_check(self.skip_version_check);
version::update_check(self.skip_version_check | self.offline.unwrap_or_default());

match self.action {
TrunkSubcommands::Build(inner) => inner.run(self.config).await,
Expand Down
6 changes: 5 additions & 1 deletion src/version/enabled/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ use crate::version::{
};
use semver::Version;
use std::time::Duration;
use tracing::instrument;

mod state;

#[instrument]
pub fn update_check(skip: bool) {
tracing::trace!("Update check");

if skip {
return;
}

tracing::debug!("Spawning update check");

// We need to spawn this in a dedicated tokio runtime, as otherwise this would block
// the current tokio runtime from existing. There seems to be an issue with where even
// the current tokio runtime from exiting. There seems to be an issue with where even
// with an aborted spawned task, tokio will wait for it to end indefinitely.
std::thread::spawn(|| {
perform_update_check();
Expand Down

0 comments on commit 81e6ab1

Please sign in to comment.