chiark / gitweb /
Move more to clisupport.rs
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 2 Jun 2021 22:57:18 +0000 (23:57 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 2 Jun 2021 22:57:18 +0000 (23:57 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
cli/clisupport.rs
cli/otter.rs

index ffb7151c0557c35f50affc60244f1658c55d7f89..06d9902f82953577e31c87fc04d5cbce01b2a37b 100644 (file)
@@ -47,6 +47,67 @@ impl From<&anyhow::Error> for ArgumentParseError {
   }
 }
 
+pub fn default_ssh_proxy_command() -> String {
+  format!("{} {}", DEFAULT_SSH_PROXY_CMD, SSH_PROXY_SUBCMD)
+}
+
+impl MainOpts {
+  pub fn game(&self) -> &str {
+    self.game.as_ref().map(|s| s.as_str()).unwrap_or_else(||{
+      eprintln!(
+        "game (table) name not specified; pass --game option");
+      exit(EXIT_USAGE);
+    })
+  }
+
+  pub fn instance(&self) -> InstanceName {
+    match self.game().strip_prefix(":") {
+      Some(rest) => {
+        InstanceName {
+          account: self.account.clone(),
+          game: rest.into(),
+        }
+      }
+      None => {
+        self.game().parse().unwrap_or_else(|e|{
+          eprintln!(
+            "game (table) name must start with : or be valid full name: {}",
+            &e);
+          exit(EXIT_USAGE);
+        })
+      }
+    }
+  }
+
+  #[throws(AE)]
+  pub fn access_account(&self) -> Conn {
+    let mut conn = connect(self)?;
+    conn.prep_access_account(self, true)?;
+    conn
+  }
+
+  #[throws(AE)]
+  pub fn access_game(&self) -> MgmtChannelForGame {
+    self.access_account()?.chan.for_game(
+      self.instance(),
+      MgmtGameUpdateMode::Online,
+    )
+  }
+
+  #[throws(AE)]
+  pub fn progressbar(&self) -> Box<dyn termprogress::Reporter> {
+    if self.verbose >= 0 {
+      termprogress::new()
+    } else {
+      termprogress::Null::new()
+    }
+  }
+}
+
+#[derive(Default,Debug)]
+pub struct NoArgs { }
+pub fn noargs(_sa: &mut NoArgs) -> ArgumentParser { ArgumentParser::new() }
+
 pub type ApMaker<'apm, T> =
   &'apm dyn for <'a> Fn(&'a mut T) -> ArgumentParser<'a>;
 
index 9c1b4193749a1915f50f6929f44da935c8264ce3..bce86444cb0591d315f78ea7648b27741dd04cca 100644 (file)
@@ -53,67 +53,6 @@ pub struct MainOpts {
   sc: &'static Subcommand,
 }
 
-fn default_ssh_proxy_command() -> String {
-  format!("{} {}", DEFAULT_SSH_PROXY_CMD, SSH_PROXY_SUBCMD)
-}
-
-impl MainOpts {
-  pub fn game(&self) -> &str {
-    self.game.as_ref().map(|s| s.as_str()).unwrap_or_else(||{
-      eprintln!(
-        "game (table) name not specified; pass --game option");
-      exit(EXIT_USAGE);
-    })
-  }
-
-  pub fn instance(&self) -> InstanceName {
-    match self.game().strip_prefix(":") {
-      Some(rest) => {
-        InstanceName {
-          account: self.account.clone(),
-          game: rest.into(),
-        }
-      }
-      None => {
-        self.game().parse().unwrap_or_else(|e|{
-          eprintln!(
-            "game (table) name must start with : or be valid full name: {}",
-            &e);
-          exit(EXIT_USAGE);
-        })
-      }
-    }
-  }
-
-  #[throws(AE)]
-  fn access_account(&self) -> Conn {
-    let mut conn = connect(self)?;
-    conn.prep_access_account(self, true)?;
-    conn
-  }
-
-  #[throws(AE)]
-  fn access_game(&self) -> MgmtChannelForGame {
-    self.access_account()?.chan.for_game(
-      self.instance(),
-      MgmtGameUpdateMode::Online,
-    )
-  }
-
-  #[throws(AE)]
-  fn progressbar(&self) -> Box<dyn termprogress::Reporter> {
-    if self.verbose >= 0 {
-      termprogress::new()
-    } else {
-      termprogress::Null::new()
-    }
-  }
-}
-
-#[derive(Default,Debug)]
-struct NoArgs { }
-fn noargs(_sa: &mut NoArgs) -> ArgumentParser { ArgumentParser::new() }
-
 #[derive(Debug)]
 pub struct Subcommand {
   pub verb: &'static str,