mirror of
https://github.com/nix-community/nurl.git
synced 2024-09-11 18:39:19 +03:00
clean up
This commit is contained in:
parent
2f2248c9ff
commit
4e54c82e9e
@ -23,7 +23,7 @@ use std::{
|
|||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
pub trait Fetcher {
|
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)]
|
#[enum_dispatch(Fetcher)]
|
||||||
@ -42,9 +42,9 @@ macro_rules! impl_fetcher {
|
|||||||
fn fetch_nix(
|
fn fetch_nix(
|
||||||
&self,
|
&self,
|
||||||
out: &mut impl ::std::io::Write,
|
out: &mut impl ::std::io::Write,
|
||||||
url: &::url::Url,
|
url: ::url::Url,
|
||||||
rev: String,
|
rev: String,
|
||||||
indent: &str,
|
indent: String,
|
||||||
) -> ::anyhow::Result<()> {
|
) -> ::anyhow::Result<()> {
|
||||||
self.fetch_nix_imp(out, url, rev, indent)
|
self.fetch_nix_imp(out, url, rev, indent)
|
||||||
}
|
}
|
||||||
@ -71,12 +71,12 @@ pub trait SimpleFlakeFetcher<'a> {
|
|||||||
fn fetch_nix_imp(
|
fn fetch_nix_imp(
|
||||||
&'a self,
|
&'a self,
|
||||||
out: &mut impl Write,
|
out: &mut impl Write,
|
||||||
url: &Url,
|
url: Url,
|
||||||
rev: String,
|
rev: String,
|
||||||
indent: &str,
|
indent: String,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let (owner, repo) = self
|
let (owner, repo) = self
|
||||||
.get_repo(url)
|
.get_repo(&url)
|
||||||
.with_context(|| format!("failed to parse {url} as a {} url", Self::FLAKE_TYPE))?;
|
.with_context(|| format!("failed to parse {url} as a {} url", Self::FLAKE_TYPE))?;
|
||||||
|
|
||||||
let hash = flake_prefetch(if let Some(host) = self.host() {
|
let hash = flake_prefetch(if let Some(host) = self.host() {
|
||||||
@ -112,9 +112,9 @@ pub trait UrlFlakeFetcher {
|
|||||||
fn fetch_nix_imp(
|
fn fetch_nix_imp(
|
||||||
&self,
|
&self,
|
||||||
out: &mut impl Write,
|
out: &mut impl Write,
|
||||||
url: &Url,
|
url: Url,
|
||||||
rev: String,
|
rev: String,
|
||||||
indent: &str,
|
indent: String,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let hash = flake_prefetch(format!(
|
let hash = flake_prefetch(format!(
|
||||||
"{}+{url}?{}={rev}",
|
"{}+{url}?{}={rev}",
|
||||||
|
@ -18,8 +18,6 @@ use std::io::stdout;
|
|||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let opts = Opts::parse();
|
let opts = Opts::parse();
|
||||||
|
|
||||||
let indent = &" ".repeat(opts.indent);
|
|
||||||
|
|
||||||
let fetcher: FetcherDispatch = match (opts.fetcher, opts.url.host()) {
|
let fetcher: FetcherDispatch = match (opts.fetcher, opts.url.host()) {
|
||||||
(None | Some(FetcherFunction::FetchFromGitHub), Some(Host::Domain("github.com"))) => {
|
(None | Some(FetcherFunction::FetchFromGitHub), Some(Host::Domain("github.com"))) => {
|
||||||
FetchFromGitHub(None).into()
|
FetchFromGitHub(None).into()
|
||||||
@ -56,12 +54,15 @@ fn main() -> Result<()> {
|
|||||||
bail!("{fetcher:?} does not support URLs without a host");
|
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(),
|
(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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user