From: Ian Jackson Date: Sat, 15 May 2021 18:06:15 +0000 (+0100) Subject: Make library list a per-table thing at managemnet API X-Git-Tag: otter-0.6.0~273 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=fa4664ed558d14e63d91bc4a32a8ada1e31e494d;p=otter.git Make library list a per-table thing at managemnet API The LibraryListByGlob command now takes a game name, and acquires an &InstanceGuard. Currently, it ignores it. The list_items method is now on MgmtChannelForGame. otter(1) LibGlobArgs now has the table name. The library-list subcommand accesses the game (and has different arguments) Signed-off-by: Ian Jackson --- diff --git a/apitest/at-otter.rs b/apitest/at-otter.rs index 1b5cf178..6da3413a 100644 --- a/apitest/at-otter.rs +++ b/apitest/at-otter.rs @@ -497,7 +497,7 @@ impl Ctx { prepare_game(&self.su().ds, &self.prctx, TABLE)?; let command = self.su().ds.ss( - "library-list wikimedia chess-yellow-?" + "library-list @table@ wikimedia chess-yellow-?" )?; let output: String = self.otter(&command)?.into(); assert!( Regex::new("(?m)^chess-yellow-K *the yellow king$")? diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 92d88581..a33a15eb 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -349,12 +349,19 @@ fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, Fine } - MC::LibraryListByGlob { glob: spec } => { - let libs = shapelib::lib_name_lookup(&spec.lib)?; - let mut results: Vec = default(); - for lib in &*libs { - results.extend(lib.list_glob(&spec.item)?); - } + MC::LibraryListByGlob { game, glob: spec } => { + let (ag, gref) = start_access_game(&game)?; + let (results, _auth) = + access_bundles( + cs,&ag,&gref, &[TP::UploadBundles], + &mut |mut _ig, _| { + let libs = shapelib::lib_name_lookup(&spec.lib)?; + let mut results: Vec = default(); + for lib in &*libs { + results.extend(lib.list_glob(&spec.item)?); + } + Ok(results) + })?; MR::LibraryItems(results) } diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 9eba6f2c..dc531d0f 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -971,10 +971,12 @@ mod delete_game { #[derive(Debug)] struct LibGlobArgs { + table_name: String, pat: shapelib::ItemSpec, } impl Default for LibGlobArgs { fn default() -> Self { Self { + table_name: default(), pat: shapelib::ItemSpec { lib: default(), item: default() }, } } } @@ -984,6 +986,8 @@ impl LibGlobArgs { ap: &'_ mut ArgumentParser<'ap> ) { use argparse::*; + ap.refer(&mut self.table_name).required() + .add_argument("TABLE-NAME",Store,"table name"); // xxx allow lack of library name to list library names ap.refer(&mut self.pat.lib).required() .add_argument("LIB-NAME",Store,"library name"); @@ -1007,7 +1011,7 @@ mod library_list { fn call(_sc: &Subcommand, ma: MainOpts, args: Vec) ->Result<(),AE> { let args = parse_args::(args, &subargs, &ok_id, None); - let mut chan = connect(&ma)?; + let mut chan = access_game(&ma, &args.table_name)?; let items = chan.list_items(&args.pat)?; for it in &items { @@ -1031,7 +1035,6 @@ mod library_add { #[derive(Default,Debug)] struct Args { - table_name: String, tlg: LibGlobArgs, adjust_markers: Option, incremental: bool, @@ -1044,8 +1047,7 @@ mod library_add { fn subargs(sa: &mut Args) -> ArgumentParser { use argparse::*; let mut ap = ArgumentParser::new(); - ap.refer(&mut sa.table_name).required() - .add_argument("TABLE-NAME",Store,"table name"); + sa.tlg.add_arguments(&mut ap); ap.refer(&mut sa.adjust_markers) .add_option(&["--no-adjust-markers"],StoreConst(Some(false)), "do not adjust the number of insertion markers, just fail") @@ -1055,7 +1057,6 @@ mod library_add { "do not place pieces already on the board; \ if they don't all fit, place as many as possible") .add_option(&["--no-incremental"],StoreConst(false),""); - sa.tlg.add_arguments(&mut ap); ap } @@ -1063,7 +1064,7 @@ mod library_add { const MAGIC: &str = "mgmt-library-load-marker"; let args = parse_args::(args, &subargs, &ok_id, None); - let mut chan = access_game(&ma, &args.table_name)?; + let mut chan = access_game(&ma, &args.tlg.table_name)?; let (pieces, _pcaliases) = chan.list_pieces()?; let markers = pieces.iter().filter(|p| p.itemname.as_str() == MAGIC) .collect::>(); diff --git a/src/commands.rs b/src/commands.rs index 786402c6..e2471ae3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -55,6 +55,7 @@ pub enum MgmtCommand { }, LibraryListByGlob { + game: InstanceName, glob: shapelib::ItemSpec, }, diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index 54f55619..ef41428d 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -122,20 +122,6 @@ impl MgmtChannel { self.cmd_withbulk(cmd, &mut io::empty(), &mut io::sink(), &mut |_|Ok(()))? } - #[throws(AE)] - pub fn list_items(&mut self, pat: &shapelib::ItemSpec) - -> Vec { - // xxx allow globbing of library names - let cmd = MgmtCommand::LibraryListByGlob { glob: pat.clone() }; - let mut items = match self.cmd(&cmd)? { - MgmtResponse::LibraryItems(items) => items, - wat => Err(anyhow!("unexpected LibraryListByGlob response: {:?}", - &wat))?, - }; - items.sort(); - items - } - pub fn for_game(self, game: InstanceName, how: MgmtGameUpdateMode) -> MgmtChannelForGame { MgmtChannelForGame { @@ -224,6 +210,24 @@ impl MgmtChannelForGame { wat => Err(anyhow!("ListPieces => {:?}", &wat))?, } } + + #[throws(AE)] + pub fn list_items(&mut self, pat: &shapelib::ItemSpec) + -> Vec { + // xxx allow globbing of library names + let cmd = MgmtCommand::LibraryListByGlob { + game: self.game.clone(), + glob: pat.clone(), + }; + let mut items = match self.cmd(&cmd)? { + MgmtResponse::LibraryItems(items) => items, + wat => Err(anyhow!("unexpected LibraryListByGlob response: {:?}", + &wat))?, + }; + items.sort(); + items + } + /* fn get_info(&mut self) -> Result< (MgmtGameResponseGameInfo, HashMap