From 1acf0b89ad40a80ab484fc7fdd24103a729dd569 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 3 Jan 2021 02:28:50 +0000 Subject: [PATCH] wip links - does not compile Signed-off-by: Ian Jackson --- src/bin/otter.rs | 43 +++++++++++++++++++++++++++++++++++-------- src/commands.rs | 4 ++-- src/spec.rs | 4 +++- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 814c05ba..79a6dccc 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -837,10 +837,10 @@ mod set_link { use super::*; - #[derive(Default,Debug)] + #[derive(Debug,Default)] struct Args { table_name: String, - kind: LinkKind, + kind: Option, url: Option, } @@ -849,19 +849,46 @@ mod set_link { let mut ap = ArgumentParser::new(); ap.refer(&mut sa.table_name).required() .add_argument("TABLE-NAME",Store,"table name"); - ap.refer(&mut sa.kind).required() - .add_argument("LINK-KIND",Store,"link kind"); + ap.refer(&mut sa.kind) + .add_argument("LINK-KIND",StoreOption,"link kind"); ap.refer(&mut sa.url) - .add_argument("URL",Store,"url (or empty for none)"); + .add_argument("URL",StoreOption,"url (or empty for none)"); ap } - fn call(_sc: &Subcommand, ma: MainOpts, args: Vec) ->Result<(),AE> { + #[throws(AE)] + fn call(_sc: &Subcommand, ma: MainOpts, args: Vec) { let args = parse_args::(args, &subargs, &ok_id, None); let mut chan = access_game(&ma, &args.table_name)?; - let mut insns = vec![]; - + match args.url { + None => { + let MgmtGameResponseGameInfo { links, .. } = chan.info()?; + for (tk, v) in links { + // xxx check syntax + match args.kind { + None => { + println!("{:<10} {}", tk, &v); + } + Some(wk) => { + if wk == tk { + println!("{}", &v); + } + } + } + } + }, + + Some(url) => { + chan.alter_game(vec![ + if url == "" { + MGI::SetLink { kind: args.kind, url } + } else { + MGI::RemoveLink { kind: args.kind } + } + ])?; + }, + } } inventory::submit!{Subcommand( diff --git a/src/commands.rs b/src/commands.rs index 3570ce55..7408d3eb 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -87,7 +87,7 @@ pub enum MgmtGameInstruction { LeaveGame(PlayerId), SetLinks(HashMap), - RemoveLink { kind: LinkKind, url: String }, + RemoveLink { kind: LinkKind }, SetLink { kind: LinkKind, url: String }, ClearLog, @@ -126,7 +126,7 @@ pub struct AccessTokenReport { pub lines: Vec } pub struct MgmtGameResponseGameInfo { pub table_size: Pos, pub players: SecondarySlotMap, - pub links: Vec<(LinkKind, String>), + pub links: Vec<(LinkKind, String)>, } #[derive(Debug,Clone,Serialize,Deserialize)] diff --git a/src/spec.rs b/src/spec.rs index 6baab355..4e4b3b25 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -14,6 +14,7 @@ use fehler::throws; use index_vec::{define_index_type, IndexVec}; use num_derive::{FromPrimitive, ToPrimitive}; use serde::{Deserialize, Serialize}; +use strum::{EnumString, Display}; use thiserror::Error; use crate::accounts::AccountName; @@ -114,7 +115,8 @@ pub enum TablePermission { } #[derive(Copy,Clone,Debug,Eq,PartialEq,Ord,PartialOrd,Hash)] -#[derive(Enum,Serialize,Deserialize)] +#[derive(Enum,EnumString,Display)] +#[derive(Serialize,Deserialize)] pub enum LinkKind { Voice, Info, -- 2.30.2