From: Ian Jackson Date: Fri, 7 Aug 2020 23:53:02 +0000 (+0100) Subject: wip X-Git-Tag: otter-0.2.0~1168 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=686013043a2cbec963ce08e32c671263c640773e;p=otter.git wip --- diff --git a/src/bin/otter.rs b/src/bin/otter.rs index a6366283..b5e72e70 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -99,8 +99,8 @@ enum Subcommand { } fn main() { - let mut mainopts : MainOpts = Default::default(); - { + let mainopts = (||{ + let mut mainopts : MainOpts = Default::default(); use argparse::*; let mut ap = ArgumentParser::new(); let mut scope = ap.refer(&mut mainopts.scope); @@ -115,14 +115,22 @@ fn main() { scope.add_option(&["--scope-unix"], StoreConst(None), "use USER scope"); - let r = ap.parse_args(); + ap.parse_args()?; mem::drop(ap); - r + /* + mainopts.scope.get_or_insert_with(||{ + let user = env::var("USER").unwrap_or_else(|e|{ + // want to call ap.error but we have to drop it because + // otherwise it still has mainopts.scope borrowed + ap.error( + }); + */ + >::Ok(mainopts) /* Cell::from_mut(&mut mainopts.scope); let opts = MainOpts::from_args(); */ - }.unwrap_or_else(|rc| std::process::exit(if rc!=0 { 12 } else { 0 })); + })().unwrap_or_else(|rc| std::process::exit(if rc!=0 { 12 } else { 0 })); println!("{:?}", &mainopts); }