diff options
Diffstat (limited to 'src/recipe.rs')
| -rw-r--r-- | src/recipe.rs | 49 |
1 files changed, 13 insertions, 36 deletions
diff --git a/src/recipe.rs b/src/recipe.rs index 5e8f9a3..870d2bf 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -122,16 +122,8 @@ pub fn parse_pkgbuild(text: &str) -> Result<Recipe> { r.backup = get("backup"); r.install = get("install").into_iter().next(); let pkgnames = get("pkgname"); - r.pkgnames = if pkgnames.is_empty() { - vec![r.pkgbase.clone()] - } else { - pkgnames.clone() - }; - r.pkg_depends = r - .pkgnames - .iter() - .map(|n| (n.clone(), r.depends.clone())) - .collect(); + r.pkgnames = if pkgnames.is_empty() { vec![r.pkgbase.clone()] } else { pkgnames.clone() }; + r.pkg_depends = r.pkgnames.iter().map(|n| (n.clone(), r.depends.clone())).collect(); r.skipgpcheck = text.contains("--skippgpcheck"); r.pkgbuild = text.to_string(); r.source_entries = parse_source_entries(&r.source)?; @@ -178,10 +170,7 @@ fn split_assign(t: &str) -> Option<(String, String)> { let (name, rest) = t.split_once('=')?; let name = name.trim(); if name.is_empty() - || !name - .chars() - .next() - .is_some_and(|c| c.is_ascii_alphabetic() || c == '_') + || !name.chars().next().is_some_and(|c| c.is_ascii_alphabetic() || c == '_') || !name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') { return None; @@ -262,10 +251,7 @@ fn parse_source_entries(list: &[String]) -> Result<Vec<SourceEntry>> { let mut branch = None; if let Some(f) = frag { for pair in f.split('&') { - let (k, v) = match pair.split_once('=') { - Some((k, v)) => (k, v), - None => continue, - }; + let Some((k, v)) = pair.split_once('=') else { continue }; match k { "commit" => commit = Some(v.to_string()), "tag" => tag = Some(v.to_string()), @@ -275,23 +261,10 @@ fn parse_source_entries(list: &[String]) -> Result<Vec<SourceEntry>> { } } let local = vcs.is_none() && !clean.contains("://"); - let filename = filename.or_else(|| { - if local { - clean.rsplit('/').next().map(|s| s.to_string()) - } else { - None - } - }); - out.push(SourceEntry { - index, - url: clean, - filename, - commit, - tag, - branch, - vcs, - local, - }); + let filename = + filename + .or_else(|| if local { clean.rsplit('/').next().map(std::string::ToString::to_string) } else { None }); + out.push(SourceEntry { index, url: clean, filename, commit, tag, branch, vcs, local }); } Ok(out) } @@ -384,7 +357,11 @@ mod tests { #[test] fn bodies_start_at_the_first_function_and_run_to_the_end() { let text = "pkgver=1.0\nsource=(x)\nbuild() {\n make\n}\n"; - assert_eq!(pkgbuild_bodies(text), "build() {\nmake\n}\n", "each line is trimmed, the bodies are compared as text"); + assert_eq!( + pkgbuild_bodies(text), + "build() {\nmake\n}\n", + "each line is trimmed, the bodies are compared as text" + ); assert_eq!(pkgbuild_bodies("pkgver=1.0\n"), ""); } |
