From: Ian Jackson Date: Fri, 7 Aug 2020 23:19:15 +0000 (+0100) Subject: parse scope X-Git-Tag: otter-0.2.0~1171 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e45d0162a62b412ca60fde73fb1366af40d68038;p=otter.git parse scope --- diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 537300ad..13e9ec85 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -60,7 +60,9 @@ struct BoundMapStore<'r, T, F: FnMut(&str) -> Result> { } impl<'f,T,F> TypedAction for MapStore -where F : 'static + Clone + FnMut(&str) -> Result { +where F : 'f + Clone + FnMut(&str) -> Result, + 'f : 'static // ideally TypedAction wuld have a lifetime parameter +{ fn bind<'x>(&self, r: Rc>) -> Action<'x> { Action::Single(Box::new(BoundMapStore { @@ -74,11 +76,11 @@ impl<'x, T, F: FnMut(&str) -> Result> IArgAction for BoundMapStore<'x, T, F> { fn parse_arg(&self, arg: &str) -> ParseResult { - let v = match self.f.borrow_mut()(arg) { + let v : T = match self.f.borrow_mut()(arg) { Ok(r) => r, Err(e) => return ParseResult::Error(e), }; - *self.r.borrow_mut(arg) = v; + **self.r.borrow_mut() = v; ParseResult::Parsed } } @@ -101,12 +103,14 @@ fn main() { { use argparse::*; let mut ap = ArgumentParser::new(); - let scope = ap.refer(&mut mainopts.scope); + let mut scope = ap.refer(&mut mainopts.scope); scope.add_option(&["--scope-server"], - Store(Some(ManagementScope::Server)), + StoreConst(Some(ManagementScope::Server)), "use Server scope"); scope.add_option(&["--scope-unix-user"], - MapStore(|user| ManagementScope::Unix { user }), + MapStore(|user| Ok(Some(ManagementScope::Unix { + user: user.into() + }))), "use specified unix user scope"); let r = ap.parse_args(); mem::drop(ap);