From: Ian Jackson Date: Sun, 15 Nov 2020 22:10:16 +0000 (+0000) Subject: wip join-game etc. X-Git-Tag: otter-0.2.0~506 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5ac3bcde9b9c96874a7e7456d915c23b639c0955;p=otter.git wip join-game etc. Signed-off-by: Ian Jackson --- diff --git a/src/bin/otter.rs b/src/bin/otter.rs index de765934..20f8a55e 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -72,7 +72,7 @@ struct MainOpts { timezone: Option, // xxx default to UrlOnStdout // xxx options for others - access: Box, + access: Option>, socket_path: String, verbose: i32, } @@ -152,15 +152,26 @@ fn main() { struct RawAccess(Box); impl Clone for RawAccess { fn clone(&self) -> Self { - Self(serde_json::from_str(serde_json::to_string(&self.0))) + (||{ + let s = serde_json::to_string(&self.0).context("ser")?; + let c = serde_json::from_str(&s).context("de")?; + Ok::<_,AE>(Self(c)) + })() + .with_context(|| format!("clone {:?} via serde failed", self)) + .unwrap() } } + impl From for RawAccess { + fn from(t: T) -> Self { RawAccess(Box::new(t)) } + } #[derive(Default,Debug)] struct RawMainArgs { account: Option, gaccount: Option, socket_path: Option, + nick: Option, + timezone: Option, access: Option, verbose: i32, config_filename: Option, @@ -183,10 +194,21 @@ fn main() { account.metavar("ACCOUNT").add_option(&["--account"], StoreOption, "use account ACCOUNT (default: unix::)"); - let urloso = Some(RawAccess(Box::new(UrlOnStdout))); + + ap.refer(&mut rma.nick).metavar("NICK").add_option( + &["--nick"], + StoreOption, + "use NICK as nick for joining games (now and in the future) \ + (default: derive from account name"); + ap.refer(&mut rma.timezone).metavar("TZ").add_option( + &["--timezone"], + StoreOption, + "display times in timezone TZ (Olson timezone name) \ + (default is to use server's default timezone)"); + let mut access = ap.refer(&mut rma.access); access.add_option(&["--url-on-stdout"], - StoreConst(urloso), + StoreConst(Some(UrlOnStdout.into())), "show game access url by printing to stdout"); let mut gaccount = ap.refer(&mut rma.gaccount); gaccount.metavar("GAME-ACCOUNT").add_option(&["--game-name-account"], @@ -210,9 +232,11 @@ fn main() { ); ap }, &|RawMainArgs { - account, gaccount, access, socket_path, verbose, config_filename, - subcommand, subargs, + account, gaccount, nick, timezone, + access, socket_path, verbose, config_filename, + subcommand, subargs, }|{ + let access = access.map(|RawAccess(a)| a); let account : AccountName = account.map(Ok::<_,APE>).unwrap_or_else(||{ let user = env::var("USER").map_err(|e| ArgumentParseError( format!("default account needs USER env var: {}", &e) @@ -234,6 +258,9 @@ fn main() { Ok((subcommand, subargs, MainOpts { account, gaccount, + access, + nick, + timezone, socket_path, verbose, })) @@ -665,8 +692,8 @@ mod join_game { let ad = AccountDetails { account: ma.account.clone(), nick: ma.nick.clone(), - timezone: wantup.y[&ma.timezone], - access: wantup.u[&ma.access], + timezone: wantup.u(&ma.timezone), + access: wantup.u(&ma.access), }; fn is_no_account(r: &Result) -> bool {