Make flakehub-flake-name truly optional

This commit is contained in:
Cole Helbling 2024-05-09 14:18:50 -07:00
parent 00e22a61b6
commit 3d9bcd16a4
2 changed files with 13 additions and 13 deletions

View file

@ -30,7 +30,7 @@ pub async fn init_cache(
flakehub_api_server: &Url, flakehub_api_server: &Url,
flakehub_api_server_netrc: &Path, flakehub_api_server_netrc: &Path,
flakehub_cache_server: &Url, flakehub_cache_server: &Url,
flakehub_flake_name: &str, flakehub_flake_name: Option<String>,
store: Arc<NixStore>, store: Arc<NixStore>,
) -> Result<State> { ) -> Result<State> {
// Parse netrc to get the credentials for api.flakehub.com. // Parse netrc to get the credentials for api.flakehub.com.
@ -121,9 +121,17 @@ pub async fn init_cache(
// Get the cache UUID for this project. // Get the cache UUID for this project.
let cache_name = { let cache_name = {
let url = flakehub_api_server let mut url = flakehub_api_server
.join("project")
.map_err(|_| Error::Config(format!("bad URL '{}'", flakehub_api_server)))?;
if let Some(flakehub_flake_name) = flakehub_flake_name {
if !flakehub_flake_name.is_empty() {
url = flakehub_api_server
.join(&format!("project/{}", flakehub_flake_name)) .join(&format!("project/{}", flakehub_flake_name))
.map_err(|_| Error::Config(format!("bad URL '{}'", flakehub_api_server)))?; .map_err(|_| Error::Config(format!("bad URL '{}'", flakehub_api_server)))?;
}
}
let response = reqwest::Client::new() let response = reqwest::Client::new()
.get(url.to_owned()) .get(url.to_owned())

View file

@ -164,15 +164,7 @@ async fn main_cli() -> Result<()> {
let flakehub_api_server_netrc = args let flakehub_api_server_netrc = args
.flakehub_api_server_netrc .flakehub_api_server_netrc
.ok_or_else(|| anyhow!("--flakehub-api-server-netrc is required"))?; .ok_or_else(|| anyhow!("--flakehub-api-server-netrc is required"))?;
let flakehub_flake_name = args let flakehub_flake_name = args.flakehub_flake_name;
.flakehub_flake_name
.ok_or_else(|| {
tracing::debug!(
"--flakehub-flake-name was not set, inferring from $GITHUB_REPOSITORY env var"
);
std::env::var("GITHUB_REPOSITORY")
})
.map_err(|_| anyhow!("--flakehub-flake-name and $GITHUB_REPOSITORY were both unset"))?;
match flakehub::init_cache( match flakehub::init_cache(
&args &args
@ -180,7 +172,7 @@ async fn main_cli() -> Result<()> {
.ok_or_else(|| anyhow!("--flakehub-api-server is required"))?, .ok_or_else(|| anyhow!("--flakehub-api-server is required"))?,
&flakehub_api_server_netrc, &flakehub_api_server_netrc,
&flakehub_cache_server, &flakehub_cache_server,
&flakehub_flake_name, flakehub_flake_name,
store.clone(), store.clone(),
) )
.await .await