chiark / gitweb /
otter(1): Move response iteration back into alter_game_adhoc
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 19 May 2021 22:03:49 +0000 (23:03 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 19 May 2021 22:59:15 +0000 (23:59 +0100)
It turns out that commands want to print responses one at a time.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs

index 707eb9ac28fd970042fe429168bec4644365a574..59bf2a69515986a2854ada5a0d9ee8058ec07c3a 100644 (file)
@@ -1398,17 +1398,15 @@ impl AdhocFormat {
   }
 
   #[throws(AE)]
-  pub fn report<T>(&self, resps: Vec<T>)
+  pub fn report<T>(&self, resp: T)
   where T: Serialize
   {
-    for resp in resps {
-      println!("{}", match self.0 {
-        "json" => serde_json::to_string(&resp).map_err(AE::from),
-        "ron"  => ron::ser::  to_string(&resp).map_err(AE::from),
-        _ => panic!(),
-      }
-          .context("re-format response")?);
+    println!("{}", match self.0 {
+      "json" => serde_json::to_string(&resp).map_err(AE::from),
+      "ron"  => ron::ser::  to_string(&resp).map_err(AE::from),
+      _ => panic!(),
     }
+        .context("re-format response")?);
   }
 }
 
@@ -1449,7 +1447,9 @@ mod alter_game_adhoc {
 
     let insns: Vec<MgmtGameInstruction> = ahf.parse(args.insns, "insn")?;
     let resps = chan.alter_game(insns,None)?;
-    ahf.report(resps)?;
+    for resp in resps {
+      ahf.report(resp)?;
+    }
 
     Ok(())
   }