From: Ian Jackson Date: Mon, 23 Nov 2020 00:32:38 +0000 (+0000) Subject: list games X-Git-Tag: otter-0.2.0~389 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=22b12460fe83a250ceffa3b6a6462845ec44938f;p=otter.git list games Signed-off-by: Ian Jackson --- diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 878599f5..c6967712 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -17,6 +17,7 @@ type AS = AccountScope; type APE = ArgumentParseError; type MC = MgmtCommand; type ME = MgmtError; +type MR = MgmtResponse; type MGI = MgmtGameInstruction; type MGR = MgmtGameResponse; type TP = TablePermission; @@ -691,6 +692,46 @@ fn access_game(ma: &MainOpts, table_name: &String) -> ConnForGame { } } +//---------- list-games ---------- + +mod list_games { + use super::*; + + #[derive(Default,Debug)] + struct Args { + all: bool, + } + + fn subargs(sa: &mut Args) -> ArgumentParser { + use argparse::*; + let mut ap = ArgumentParser::new(); + ap.refer(&mut sa.all) + .add_option(&["--all"],StoreTrue, + "list all games, not just yours"); + ap + } + + fn call(_sc: &Subcommand, ma: MainOpts, args: Vec) ->Result<(),AE> { + let args = parse_args::(args, &subargs, &ok_id, None); + let mut conn = connect(&ma)?; + let mut games = match conn.cmd(&MC::ListGames { all: Some(args.all) })? { + MR::GamesList(g) => g, + x => throw!(anyhow!("unexpected response to ListGames: {:?}", &x)), + }; + games.sort(); + for g in games { + println!("{}", &g); + } + Ok(()) + } + + inventory::submit!{Subcommand( + "list-games", + "List games", + call, + )} +} + //---------- reset-game ---------- mod reset_game {