From 64e19190449d5ad0cd6ce7a12519e31cd345ae30 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 15 Aug 2020 11:16:50 +0100 Subject: [PATCH] work around rustc message lossage --- src/bin/otter.rs | 86 +++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 6bb42731..749a93f4 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -188,53 +188,65 @@ fn connect(_ma: &MainOpts) -> MgmtChannel { chan } -inventory::submit!{Subcommand( - "create-table", - "Create a new table", - do_create_table, -)} +mod create_table { + use super::*; -#[throws(E)] -fn do_create_table(_sc: &Subcommand, ma: MainOpts, args: Vec) { #[derive(Default,Debug)] struct Args { name: String, file: String, } - let args = parse_args::(args, - &|ma|{ - use argparse::*; - let mut ap = ArgumentParser::new(); - ap.refer(&mut ma.name).required() - .add_argument("TABLE-NAME",Store,"table name"); - ap.refer(&mut ma.file).required() - .add_argument("TABLE-SPEC-TOML",Store,"table spec"); - ap - }, &|_ma|{ - Ok(()) - }, None); - let spec = (||{ - let mut f = File::open(&args.file).context("open")?; - let mut buf = String::new(); - f.read_to_string(&mut buf).context("read")?; - let spec : TableSpec = toml::de::from_str(&buf).context("parse")?; - >::Ok(spec) - })().context("game spec toml").context(&args.file)?; + fn subargs(sa: &mut Args) -> ArgumentParser { + use argparse::*; + let mut ap = ArgumentParser::new(); + ap.refer(&mut sa.name).required() + .add_argument("TABLE-NAME",Store,"table name"); + ap.refer(&mut sa.file).required() + .add_argument("TABLE-SPEC-TOML",Store,"table spec"); + ap + } + + #[throws(ArgumentParseError)] + fn complete(_sa: &mut Args) { } + + #[throws(E)] + fn call(_sc: &Subcommand, ma: MainOpts, args: Vec) { + let args = parse_args::(args, &subargs, &complete, None); - let chan = connect(&ma)?; + let spec = (||{ + let mut f = File::open(&args.file).context("open")?; + let mut buf = String::new(); + f.read_to_string(&mut buf).context("read")?; + let spec : TableSpec = toml::de::from_str(&buf).context("parse")?; + >::Ok(spec) + })().context("game spec toml").with_context(|| args.file.to_owned())?; - /* + let chan = connect(&ma)?; - chan.cmd(MgmtCommand::CreateGame { - CreateGame { - name: args.name, - insns: vec![ - MgmtGameInstruction { + /* - }, - ]*/ + chan.cmd(MgmtCommand::CreateGame { + CreateGame { + name: args.name, + insns: vec![ + MgmtGameInstruction { - eprintln!("CREATE-TABLE {:?} {:?}", &ma, &args); - Ok(()) + }, + ]*/ + + eprintln!("CREATE-TABLE {:?} {:?}", &ma, &args); + } + + inventory::submit!{Subcommand( + "create-table", + "Create a new table", + call, + )} } + + +/* +impl Default for Args { + fn default() -> Args { Args { name: String::new(), file: String::new() }} +}*/ -- 2.30.2