From 3fd6eeb2083e52bc16a2ab5f410ba5df439f9d62 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 5 Nov 2024 21:11:26 -0500 Subject: [PATCH] Make the FlakeHubArg a generic Trinary so we can use it for GHA Cache too --- magic-nix-cache/src/main.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/magic-nix-cache/src/main.rs b/magic-nix-cache/src/main.rs index 3b06ed5..1991e2a 100644 --- a/magic-nix-cache/src/main.rs +++ b/magic-nix-cache/src/main.rs @@ -114,7 +114,7 @@ struct Args { /// Whether to use the FlakeHub binary cache. #[arg(long)] - use_flakehub: Option>, + use_flakehub: Option>, /// URL to which to post startup notification. #[arg(long)] @@ -130,17 +130,17 @@ struct Args { } #[derive(Debug, Clone, Copy, PartialEq, clap::ValueEnum)] -pub enum FlakeHubArg { +pub enum CacheTrinary { NoPreference, Enabled, Disabled, } -impl From>> for FlakeHubArg { - fn from(b: Option>) -> Self { +impl From>> for CacheTrinary { + fn from(b: Option>) -> Self { match b { - None => FlakeHubArg::NoPreference, - Some(None) => FlakeHubArg::Enabled, + None => CacheTrinary::NoPreference, + Some(None) => CacheTrinary::Enabled, Some(Some(v)) => v, } } @@ -170,7 +170,7 @@ impl Args { ))); } - if environment.is_gitlab_ci() && self.flakehub_preference() != FlakeHubArg::Enabled { + if environment.is_gitlab_ci() && self.flakehub_preference() != CacheTrinary::Enabled { return Err(error::Error::Config(String::from( "you must set --use-flakehub in GitLab CI", ))); @@ -179,7 +179,7 @@ impl Args { Ok(()) } - fn flakehub_preference(&self) -> FlakeHubArg { + fn flakehub_preference(&self) -> CacheTrinary { self.use_flakehub.into() } } @@ -287,17 +287,17 @@ async fn main_cli() -> Result<()> { dnixd_available, ) { // User has explicitly pyassed --use-flakehub=disabled, so just straight up don't - (FlakeHubArg::Disabled, _, _) => { + (CacheTrinary::Disabled, _, _) => { tracing::info!("Disabling FlakeHub cache."); None } // User has no preference, did not pass a netrc, and determinate-nixd is not available - (FlakeHubArg::NoPreference, None, Dnixd::Missing) => None, + (CacheTrinary::NoPreference, None, Dnixd::Missing) => None, // Use it when determinate-nixd is available, and let the user know what's going on (pref, user_netrc_path, Dnixd::Available) => { - if pref == FlakeHubArg::NoPreference { + if pref == CacheTrinary::NoPreference { tracing::info!("Enabling FlakeHub cache because determinate-nixd is available."); } @@ -312,7 +312,7 @@ async fn main_cli() -> Result<()> { (_, Some(path), Dnixd::Missing) => Some(FlakeHubAuthSource::Netrc(path.to_owned())), // User explicitly turned on flakehub cache, but we have no netrc and determinate-nixd is not present - (FlakeHubArg::Enabled, None, Dnixd::Missing) => { + (CacheTrinary::Enabled, None, Dnixd::Missing) => { return Err(anyhow!( "--flakehub-api-server-netrc is required when determinate-nixd is unavailable" ));