This commit is contained in:
figsoda 2022-12-30 12:38:41 -05:00
parent 2f2248c9ff
commit 4e54c82e9e
2 changed files with 13 additions and 12 deletions

View File

@ -23,7 +23,7 @@ use std::{
#[enum_dispatch]
pub trait Fetcher {
fn fetch_nix(&self, out: &mut impl Write, url: &Url, rev: String, indent: &str) -> Result<()>;
fn fetch_nix(&self, out: &mut impl Write, url: Url, rev: String, indent: String) -> Result<()>;
}
#[enum_dispatch(Fetcher)]
@ -42,9 +42,9 @@ macro_rules! impl_fetcher {
fn fetch_nix(
&self,
out: &mut impl ::std::io::Write,
url: &::url::Url,
url: ::url::Url,
rev: String,
indent: &str,
indent: String,
) -> ::anyhow::Result<()> {
self.fetch_nix_imp(out, url, rev, indent)
}
@ -71,12 +71,12 @@ pub trait SimpleFlakeFetcher<'a> {
fn fetch_nix_imp(
&'a self,
out: &mut impl Write,
url: &Url,
url: Url,
rev: String,
indent: &str,
indent: String,
) -> Result<()> {
let (owner, repo) = self
.get_repo(url)
.get_repo(&url)
.with_context(|| format!("failed to parse {url} as a {} url", Self::FLAKE_TYPE))?;
let hash = flake_prefetch(if let Some(host) = self.host() {
@ -112,9 +112,9 @@ pub trait UrlFlakeFetcher {
fn fetch_nix_imp(
&self,
out: &mut impl Write,
url: &Url,
url: Url,
rev: String,
indent: &str,
indent: String,
) -> Result<()> {
let hash = flake_prefetch(format!(
"{}+{url}?{}={rev}",

View File

@ -18,8 +18,6 @@ use std::io::stdout;
fn main() -> Result<()> {
let opts = Opts::parse();
let indent = &" ".repeat(opts.indent);
let fetcher: FetcherDispatch = match (opts.fetcher, opts.url.host()) {
(None | Some(FetcherFunction::FetchFromGitHub), Some(Host::Domain("github.com"))) => {
FetchFromGitHub(None).into()
@ -56,12 +54,15 @@ fn main() -> Result<()> {
bail!("{fetcher:?} does not support URLs without a host");
}
(Some(FetcherFunction::Fetchgit), _) | (None, _) => Fetchgit.into(),
(None | Some(FetcherFunction::Fetchgit), _) => Fetchgit.into(),
(Some(FetcherFunction::Fetchhg), _) => Fetchhg.into(),
};
fetcher.fetch_nix(&mut stdout().lock(), &opts.url, opts.rev, indent)?;
let out = &mut stdout().lock();
let indent = " ".repeat(opts.indent);
fetcher.fetch_nix(out, opts.url, opts.rev, indent)?;
Ok(())
}