chiark / gitweb /
Move admin.rs out of otter.rs and forgame.rs
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 2 Jun 2021 23:13:10 +0000 (00:13 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 2 Jun 2021 23:13:10 +0000 (00:13 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
cli/admin.rs [new file with mode: 0644]
cli/forgame.rs
cli/otter.rs

diff --git a/cli/admin.rs b/cli/admin.rs
new file mode 100644 (file)
index 0000000..fbd2607
--- /dev/null
@@ -0,0 +1,85 @@
+// Copyright 2020-2021 Ian Jackson and contributors to Otter
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// There is NO WARRANTY.
+
+// todo: delete-account
+
+use super::*;
+
+//---------- list-games ----------
+
+mod list_games {
+  use super::*;
+
+  #[derive(Default,Debug)]
+  struct Args {
+    all: bool,
+  }
+
+  fn subargs(sa: &mut Args) -> ArgumentParser {
+    use argparse::*;
+    let mut ap = ArgumentParser::new();
+    ap.refer(&mut sa.all)
+      .add_option(&["--all"],StoreTrue,
+                  "user superuser access to list *all* games");
+    ap
+  }
+
+  fn call(SCCA{ mut out, ma, args,.. }:SCCA) -> Result<(),AE> {
+    let args = parse_args::<Args,_>(args, &subargs, &ok_id, None);
+    let mut conn = connect(&ma)?;
+    let mut games = match conn.cmd(&MC::ListGames { all: Some(args.all) })? {
+      MR::GamesList(g) => g,
+      x => throw!(anyhow!("unexpected response to ListGames: {:?}", &x)),
+    };
+    games.sort();
+    for g in games {
+      writeln!(out, "{}", &g)?;
+    }
+    Ok(())
+  }
+
+  inventory_subcmd!{
+    "list-games",
+    "List games",
+  }
+}
+
+//---------- list-accounts ----------
+
+mod list_accounts {
+  use super::*;
+
+  #[derive(Default,Debug)]
+  struct Args {
+    all: bool,
+  }
+
+  fn subargs(sa: &mut Args) -> ArgumentParser {
+    use argparse::*;
+    let mut ap = ArgumentParser::new();
+    ap.refer(&mut sa.all)
+      .add_option(&["--all"],StoreTrue,
+                  "user superuser access to list all accounts");
+    ap
+  }
+
+  #[throws(AE)]
+  fn call(SCCA{ mut out, ma, args,.. }:SCCA) {
+    let args = parse_args::<Args,_>(args, &subargs, &ok_id, None);
+    let mut conn = connect(&ma)?;
+    let all = Some(args.all);
+    let accounts = match conn.cmd(&MC::ListAccounts { all })? {
+      MR::AccountsList(g) => g,
+      x => throw!(anyhow!("unexpected response to ListAccounts: {:?}", &x)),
+    };
+    for a in accounts {
+      writeln!(out, "{}", a)?;
+    }
+  }
+
+  inventory_subcmd!{
+    "list-accounts",
+    "List accounts in your account scope",
+  }
+}
index e5116eed1b30f365884a4d1294d4b40405777687..e562cd3afd6c84afbd080bb2efe8671522c3ede0 100644 (file)
@@ -5,47 +5,7 @@
 use super::*;
 use super::usebundles::*;
 
-//---------- list-games ----------
-
-mod list_games {
-  use super::*;
-
-  #[derive(Default,Debug)]
-  struct Args {
-    all: bool,
-  }
-
-  fn subargs(sa: &mut Args) -> ArgumentParser {
-    use argparse::*;
-    let mut ap = ArgumentParser::new();
-    ap.refer(&mut sa.all)
-      .add_option(&["--all"],StoreTrue,
-                  "user superuser access to list *all* games");
-    ap
-  }
-
-  fn call(SCCA{ mut out, ma, args,.. }:SCCA) -> Result<(),AE> {
-    let args = parse_args::<Args,_>(args, &subargs, &ok_id, None);
-    let mut conn = connect(&ma)?;
-    let mut games = match conn.cmd(&MC::ListGames { all: Some(args.all) })? {
-      MR::GamesList(g) => g,
-      x => throw!(anyhow!("unexpected response to ListGames: {:?}", &x)),
-    };
-    games.sort();
-    for g in games {
-      writeln!(out, "{}", &g)?;
-    }
-    Ok(())
-  }
-
-  inventory_subcmd!{
-    "list-games",
-    "List games",
-  }
-}
-
 // todo: list-players
-// todo: delete-account
 
 //---------- reset-game ----------
 
index 864e704efb6f49c634adbeb8516f8439241faf83..11b46dcd5f4392a4b72a9eb8ef84a8c639056206 100644 (file)
@@ -30,6 +30,7 @@ pub mod clisupport;
 use clisupport::*;
 
 mod adhoc;
+mod admin;
 mod forssh;
 mod forgame;
 mod usebundles;
@@ -323,42 +324,3 @@ fn main() {
   (mo.sc.call)(SubCommandCallArgs { ma: mo, out: stdout, args: subargs })
     .unwrap_or_else(|e| e.end_process(12));
 }
-
-//---------- list-accounts ----------
-
-mod list_accounts {
-  use super::*;
-
-  #[derive(Default,Debug)]
-  struct Args {
-    all: bool,
-  }
-
-  fn subargs(sa: &mut Args) -> ArgumentParser {
-    use argparse::*;
-    let mut ap = ArgumentParser::new();
-    ap.refer(&mut sa.all)
-      .add_option(&["--all"],StoreTrue,
-                  "user superuser access to list all accounts");
-    ap
-  }
-
-  #[throws(AE)]
-  fn call(SCCA{ mut out, ma, args,.. }:SCCA) {
-    let args = parse_args::<Args,_>(args, &subargs, &ok_id, None);
-    let mut conn = connect(&ma)?;
-    let all = Some(args.all);
-    let accounts = match conn.cmd(&MC::ListAccounts { all })? {
-      MR::AccountsList(g) => g,
-      x => throw!(anyhow!("unexpected response to ListAccounts: {:?}", &x)),
-    };
-    for a in accounts {
-      writeln!(out, "{}", a)?;
-    }
-  }
-
-  inventory_subcmd!{
-    "list-accounts",
-    "List accounts in your account scope",
-  }
-}