Add fetch-channel command

This commit is contained in:
Tobias Reisinger 2023-11-17 17:32:15 +01:00
parent 970c1ee2c2
commit 244a7073fe
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
9 changed files with 183 additions and 54 deletions

View file

@ -31,7 +31,12 @@ pub struct ChannelsArgs {
pub struct FetchArgs {
#[arg(long)]
strict_client: bool,
client: String,
#[arg(long)]
strict_channel: bool,
#[arg(long)]
channel: Option<String>,
#[arg(long)]
client: Option<String>,
}
#[derive(Args)]
@ -58,12 +63,29 @@ pub struct UpdateArgs {
speakers: Option<bool>,
}
impl FetchArgs {
pub fn client(&self, connection: &mut Telnet) -> Result<Option<ResponseClient>, String> {
utils::find_client(connection, &self.client, self.strict_client)
pub fn want_channel(&self) -> bool {
self.channel.is_some()
}
pub fn want_client(&self) -> bool {
self.client.is_some()
}
pub fn channel(&self, connection: &mut Telnet) -> Result<Option<ResponseChannel>, String> {
if let Some(channel) = &self.channel {
utils::find_channel(connection, channel, self.strict_channel)
} else {
Err("No channel specified.".to_string())
}
}
pub fn client(&self, connection: &mut Telnet) -> Result<Option<ResponseClient>, String> {
if let Some(client) = &self.client {
utils::find_client(connection, client, self.strict_client)
} else {
Err("No client specified.".to_string())
}
}
}
impl MoveArgs {