chiark / gitweb /
list glob
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Sep 2020 12:06:59 +0000 (13:06 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Sep 2020 12:06:59 +0000 (13:06 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs
src/cmdlistener.rs
src/commands.rs
src/shapelib.rs

index 0b3f641c2ba6cc3424b2857b4a37d85f4acea005..59d63b0635fae03fe84766dcd96b0b90d6d71085 100644 (file)
@@ -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(
index 6f9757f620e1d07f6e1c1e5e7cdca407a703644e..8ab43a20a43c9918868358d034127ee9cf0d8712 100644 (file)
@@ -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)
     },
   }
 }
index 72820013503ed8b052eb0f051317a137199d0899..8a09ed0e27008cc60b4145b87785db2523783bd2 100644 (file)
@@ -26,6 +26,7 @@ pub enum MgmtResponse {
   Error { error: MgmtError },
   AlterGame { error: Option<MgmtError>, responses: Vec<MgmtGameResponse> },
   GamesList(Vec<Arc<InstanceName>>),
+  LibraryItems(Vec<shapelib::ItemEnquiryData>),
 }
 
 #[derive(Debug,Serialize,Deserialize)]
index 44cedf3145620d5bf1d5762759fd4253f2c86191..044733228dfbdc8bfb72dc576efc3dfd526b5684 100644 (file)
@@ -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<ItemEnquiryResult> {
+  pub fn list_glob(&self, pat: &str) -> Vec<ItemEnquiryData> {
     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())),