From f558eec3927660df572d80d6aea82f25a271f114 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 2 Jun 2021 23:57:18 +0100 Subject: [PATCH] Move more to clisupport.rs Signed-off-by: Ian Jackson --- cli/clisupport.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++++ cli/otter.rs | 61 ----------------------------------------------- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/cli/clisupport.rs b/cli/clisupport.rs index ffb7151c..06d9902f 100644 --- a/cli/clisupport.rs +++ b/cli/clisupport.rs @@ -47,6 +47,67 @@ impl From<&anyhow::Error> for ArgumentParseError { } } +pub fn default_ssh_proxy_command() -> String { + format!("{} {}", DEFAULT_SSH_PROXY_CMD, SSH_PROXY_SUBCMD) +} + +impl MainOpts { + pub fn game(&self) -> &str { + self.game.as_ref().map(|s| s.as_str()).unwrap_or_else(||{ + eprintln!( + "game (table) name not specified; pass --game option"); + exit(EXIT_USAGE); + }) + } + + pub fn instance(&self) -> InstanceName { + match self.game().strip_prefix(":") { + Some(rest) => { + InstanceName { + account: self.account.clone(), + game: rest.into(), + } + } + None => { + self.game().parse().unwrap_or_else(|e|{ + eprintln!( + "game (table) name must start with : or be valid full name: {}", + &e); + exit(EXIT_USAGE); + }) + } + } + } + + #[throws(AE)] + pub fn access_account(&self) -> Conn { + let mut conn = connect(self)?; + conn.prep_access_account(self, true)?; + conn + } + + #[throws(AE)] + pub fn access_game(&self) -> MgmtChannelForGame { + self.access_account()?.chan.for_game( + self.instance(), + MgmtGameUpdateMode::Online, + ) + } + + #[throws(AE)] + pub fn progressbar(&self) -> Box { + if self.verbose >= 0 { + termprogress::new() + } else { + termprogress::Null::new() + } + } +} + +#[derive(Default,Debug)] +pub struct NoArgs { } +pub fn noargs(_sa: &mut NoArgs) -> ArgumentParser { ArgumentParser::new() } + pub type ApMaker<'apm, T> = &'apm dyn for <'a> Fn(&'a mut T) -> ArgumentParser<'a>; diff --git a/cli/otter.rs b/cli/otter.rs index 9c1b4193..bce86444 100644 --- a/cli/otter.rs +++ b/cli/otter.rs @@ -53,67 +53,6 @@ pub struct MainOpts { sc: &'static Subcommand, } -fn default_ssh_proxy_command() -> String { - format!("{} {}", DEFAULT_SSH_PROXY_CMD, SSH_PROXY_SUBCMD) -} - -impl MainOpts { - pub fn game(&self) -> &str { - self.game.as_ref().map(|s| s.as_str()).unwrap_or_else(||{ - eprintln!( - "game (table) name not specified; pass --game option"); - exit(EXIT_USAGE); - }) - } - - pub fn instance(&self) -> InstanceName { - match self.game().strip_prefix(":") { - Some(rest) => { - InstanceName { - account: self.account.clone(), - game: rest.into(), - } - } - None => { - self.game().parse().unwrap_or_else(|e|{ - eprintln!( - "game (table) name must start with : or be valid full name: {}", - &e); - exit(EXIT_USAGE); - }) - } - } - } - - #[throws(AE)] - fn access_account(&self) -> Conn { - let mut conn = connect(self)?; - conn.prep_access_account(self, true)?; - conn - } - - #[throws(AE)] - fn access_game(&self) -> MgmtChannelForGame { - self.access_account()?.chan.for_game( - self.instance(), - MgmtGameUpdateMode::Online, - ) - } - - #[throws(AE)] - fn progressbar(&self) -> Box { - if self.verbose >= 0 { - termprogress::new() - } else { - termprogress::Null::new() - } - } -} - -#[derive(Default,Debug)] -struct NoArgs { } -fn noargs(_sa: &mut NoArgs) -> ArgumentParser { ArgumentParser::new() } - #[derive(Debug)] pub struct Subcommand { pub verb: &'static str, -- 2.30.2