From e45d0162a62b412ca60fde73fb1366af40d68038 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 8 Aug 2020 00:19:15 +0100 Subject: [PATCH] parse scope --- src/bin/otter.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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); -- 2.30.2