From 38e211da2f37d40d458a52ee07c57a1ee694b20e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 27 Sep 2020 13:06:59 +0100 Subject: [PATCH] list glob Signed-off-by: Ian Jackson --- src/bin/otter.rs | 2 +- src/cmdlistener.rs | 6 ++++-- src/commands.rs | 1 + src/shapelib.rs | 6 +++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 0b3f641c..59d63b06 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -222,7 +222,7 @@ impl Conn { self.chan.write(&cmd).context("send command")?; let resp = self.chan.read().context("read response")?; match &resp { - Fine | GamesList{..} => { }, + Fine | GamesList{..} | LibraryItems(_) => { }, AlterGame { error: None, .. } => { }, Error { error } => { Err(error.clone()).context( diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index 6f9757f6..8ab43a20 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -109,8 +109,10 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { execute_for_game(cs, &mut g, insns, how)? }, - LibraryListByGlob { glob: _pat } => { - panic!() //xxx + LibraryListByGlob { glob: spec } => { + let lib = shapelib::libs_lookup(&spec.lib)?; + let results = lib.list_glob(&spec.item)?; + LibraryItems(results) }, } } diff --git a/src/commands.rs b/src/commands.rs index 72820013..8a09ed0e 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -26,6 +26,7 @@ pub enum MgmtResponse { Error { error: MgmtError }, AlterGame { error: Option, responses: Vec }, GamesList(Vec>), + LibraryItems(Vec), } #[derive(Debug,Serialize,Deserialize)] diff --git a/src/shapelib.rs b/src/shapelib.rs index 44cedf31..04473322 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -142,7 +142,7 @@ struct Item { } #[derive(Debug,Clone,Serialize,Deserialize)] -struct ItemEnquiryResult { +pub struct ItemEnquiryData { pub itemname: String, pub f0desc: Html, pub f0bbox: [Pos; 2], @@ -239,7 +239,7 @@ impl Contents { } #[throws(MgmtError)] - fn list_glob(&self, pat: &str) -> Vec { + pub fn list_glob(&self, pat: &str) -> Vec { let pat = glob::Pattern::new(pat).map_err(|pe| MgmtError::BadGlob { pat: pat.to_string(), msg: pe.msg.to_string() })?; let mut out = vec![]; @@ -251,7 +251,7 @@ impl Contents { Ok(r) => r, }; let f0bbox = loaded.bbox_approx(); - let ier = ItemEnquiryResult { + let ier = ItemEnquiryData { itemname: k.clone(), f0bbox, f0desc: loaded.describe_html(Some(Default::default())), -- 2.30.2