Make the FlakeHubArg a generic Trinary so we can use it for GHA Cache too
This commit is contained in:
parent
cf183317a5
commit
3fd6eeb208
|
@ -114,7 +114,7 @@ struct Args {
|
|||
|
||||
/// Whether to use the FlakeHub binary cache.
|
||||
#[arg(long)]
|
||||
use_flakehub: Option<Option<FlakeHubArg>>,
|
||||
use_flakehub: Option<Option<CacheTrinary>>,
|
||||
|
||||
/// 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<Option<Option<FlakeHubArg>>> for FlakeHubArg {
|
||||
fn from(b: Option<Option<FlakeHubArg>>) -> Self {
|
||||
impl From<Option<Option<CacheTrinary>>> for CacheTrinary {
|
||||
fn from(b: Option<Option<CacheTrinary>>) -> 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"
|
||||
));
|
||||
|
|
Loading…
Reference in a new issue