From e6069b5a56f5f37a981d1f7481a49df7a36f7365 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 22 Aug 2020 16:54:52 +0100 Subject: [PATCH] rationalise command enums --- src/bin/otter.rs | 7 ++++--- src/cmdlistener.rs | 22 +++++++++++----------- src/commands.rs | 14 +++++++------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index eac8c41e..a8e77c10 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -189,7 +189,7 @@ impl Conn { self.chan.write(&cmd).context("send command")?; let resp = self.chan.read().context("read response")?; match &resp { - Fine{..} | GamesList{..} => { }, + Fine | GamesList{..} => { }, AlterGame { error: None, .. } => { }, Error { error } => { Err(error.clone()).context(format!("response to: {:?}",&cmd))?; @@ -270,7 +270,7 @@ fn connect(ma: &MainOpts) -> Conn { let unix = UnixStream::connect(SOCKET_PATH).context("connect to server")?; let chan = MgmtChannel::new(unix)?; let mut chan = Conn { chan }; - chan.cmd(&MgmtCommand::SetScope { scope: ma.scope.clone().unwrap() })?; + chan.cmd(&MgmtCommand::SetScope(ma.scope.clone().unwrap()))?; chan } @@ -328,11 +328,12 @@ fn setup_table(chan: &mut ConnForGame, spec: &TableSpec) -> Result<(),AE> { players: resetreport.clone(), }); insns.push(MgmtGameInstruction::ReportPlayerAccesses { + // xxx not needed players: resetreport.clone(), }); let mut got_tokens = None; chan.alter_game(insns, &mut |response| { - if let MgmtGameResponse::PlayerAccessTokens { tokens } = response { + if let MgmtGameResponse::PlayerAccessTokens(tokens) = response { got_tokens = Some(tokens.clone()); } Ok(()) diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index f5d5abc6..21ea5af2 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -193,13 +193,13 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { eprintln!("command connection {}: executing {:?}", &cs.desc, &cmd); match cmd { - Noop { } => Fine { }, + Noop => Fine, - SetScope{ scope: wanted_scope } => { + SetScope(wanted_scope) => { let authorised : AuthorisedSatisfactory = authorise_scope(cs, &wanted_scope)?; cs.scope = Some(authorised.into_inner()); - Fine { } + Fine }, CreateGame { name, insns } => { @@ -229,7 +229,7 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { e })?; - Fine { } + Fine }, ListGames { all } => { @@ -243,7 +243,7 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { }; let mut games = Instance::list_names(scope); games.sort_unstable(); - GamesList { games } + GamesList(games) }, MgmtCommand::AlterGame { name, insns, how} => { @@ -369,7 +369,7 @@ fn execute_game_insn(cs: &CommandStream, use MgmtGameInstruction::*; use MgmtGameResponse::*; match update { - Noop { } => (vec![], vec![], Fine { }), + Noop { } => (vec![], vec![], Fine), MgmtGameInstruction::AddPlayer(pl) => { let player = ig.player_new(pl)?; @@ -384,7 +384,7 @@ fn execute_game_insn(cs: &CommandStream, RemovePlayer(player) => { ig.player_remove(player)?; - (vec![], vec![], Fine{}) + (vec![], vec![], Fine) }, GetPlayers { } => { @@ -395,12 +395,12 @@ fn execute_game_insn(cs: &CommandStream, ResetPlayerAccesses { players } => { let tokens = ig.players_access_reset(&players)? .drain(0..).map(|token| vec![token]).collect(); - (vec![], vec![], PlayerAccessTokens { tokens }) + (vec![], vec![], PlayerAccessTokens(tokens)) } ReportPlayerAccesses { players } => { let tokens = ig.players_access_report(&players)?; - (vec![], vec![], PlayerAccessTokens { tokens }) + (vec![], vec![], PlayerAccessTokens(tokens)) } SetFixedPlayerAccess { player, token } => { @@ -413,7 +413,7 @@ fn execute_game_insn(cs: &CommandStream, ig.player_access_register_fixed( player, token, authorised )?; - (vec![], vec![], Fine{}) + (vec![], vec![], Fine) } AddPiece(PiecesSpec{ pos,posd,count,face,info }) => { @@ -445,7 +445,7 @@ fn execute_game_insn(cs: &CommandStream, (updates, vec![ LogEntry { html: format!("The facilitaror added {} pieces", count), }], - Fine { } + Fine ) }, } diff --git a/src/commands.rs b/src/commands.rs index 207be925..cdd3b5f3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -3,8 +3,8 @@ use crate::imports::*; #[derive(Debug,Serialize,Deserialize)] pub enum MgmtCommand { - Noop { }, - SetScope { scope: ManagementScope }, + Noop, + SetScope(ManagementScope), CreateGame { name: String, insns: Vec }, ListGames { all: Option, }, AlterGame { @@ -15,15 +15,15 @@ pub enum MgmtCommand { #[derive(Debug,Serialize,Deserialize)] pub enum MgmtResponse { - Fine { }, + Fine, Error { error: MgmtError }, AlterGame { error: Option, responses: Vec }, - GamesList { games: Vec> }, + GamesList(Vec>), } #[derive(Debug,Serialize,Deserialize)] pub enum MgmtGameInstruction { - Noop { }, + Noop, AddPiece(PiecesSpec), // todo: RemovePiece AddPlayer(PlayerState), @@ -36,9 +36,9 @@ pub enum MgmtGameInstruction { #[derive(Debug,Serialize,Deserialize)] pub enum MgmtGameResponse { - Fine { }, + Fine, AddPlayer(PlayerId), - PlayerAccessTokens { tokens: Vec> }, + PlayerAccessTokens(Vec>), Players(PlayerMap), } -- 2.30.2