From 50e01f306d5683a66cb0f7fd8177ded4181a8618 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 3 Jun 2021 00:13:10 +0100 Subject: [PATCH] Move admin.rs out of otter.rs and forgame.rs Signed-off-by: Ian Jackson --- cli/admin.rs | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ cli/forgame.rs | 40 ------------------------ cli/otter.rs | 40 +----------------------- 3 files changed, 86 insertions(+), 79 deletions(-) create mode 100644 cli/admin.rs diff --git a/cli/admin.rs b/cli/admin.rs new file mode 100644 index 00000000..fbd26075 --- /dev/null +++ b/cli/admin.rs @@ -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, &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, &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", + } +} diff --git a/cli/forgame.rs b/cli/forgame.rs index e5116eed..e562cd3a 100644 --- a/cli/forgame.rs +++ b/cli/forgame.rs @@ -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, &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 ---------- diff --git a/cli/otter.rs b/cli/otter.rs index 864e704e..11b46dcd 100644 --- a/cli/otter.rs +++ b/cli/otter.rs @@ -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, &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", - } -} -- 2.30.2