diff --git a/src/fetcher/mod.rs b/src/fetcher/mod.rs index 1dc9141..d6456b4 100644 --- a/src/fetcher/mod.rs +++ b/src/fetcher/mod.rs @@ -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}", diff --git a/src/main.rs b/src/main.rs index 6d69548..03cd71b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(()) }