From 2cf9cb745c4b064a713123830839ff3c4204688a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 20 May 2021 01:50:33 +0100 Subject: [PATCH] otter(!): Break up read_spec (for uploadable specs) Signed-off-by: Ian Jackson --- src/bin/otter.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index d98af03b..a117733c 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -616,14 +616,26 @@ impl SpecParse for SpecRaw { } impl SpecRaw { pub fn new() -> Self { Self(default()) } } +fn spec_arg_is_path(specname: &str) -> Option { + if specname.contains('/') { + Some(specname.to_string()) + } else { + None + } +} + #[throws(AE)] -fn read_spec(ma: &MainOpts, specname: &str, _: P) -> P::T +fn read_spec(ma: &MainOpts, specname: &str, p: P) -> P::T +{ + let filename = spec_arg_is_path(specname).unwrap_or_else( + || format!("{}/{}.{}.toml", &ma.spec_dir, specname, P::S::FNCOMP) + ); + read_spec_from_path(filename, p)? +} + +#[throws(AE)] +fn read_spec_from_path(filename: String, _: P) -> P::T { - let filename = if specname.contains('/') { - specname.to_string() - } else { - format!("{}/{}.{}.toml", &ma.spec_dir, specname, P::S::FNCOMP) - }; (||{ let mut f = File::open(&filename).context("open")?; let mut buf = String::new(); -- 2.30.2