Auto-reformat code
This commit is contained in:
parent
463bc99b9c
commit
1002782e8f
8 changed files with 41 additions and 33 deletions
|
@ -1,5 +1,6 @@
|
|||
use clap::{Parser, Subcommand, Args};
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use telnet::Telnet;
|
||||
|
||||
use crate::parameter::{Parameter, ParameterList};
|
||||
use crate::response::channel::ResponseChannel;
|
||||
use crate::response::client::ResponseClient;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use telnet::Telnet;
|
||||
use telnet::Event::Data;
|
||||
use crate::parameter::ParameterList;
|
||||
use telnet::Telnet;
|
||||
|
||||
use crate::parameter::ParameterList;
|
||||
use crate::response::Response;
|
||||
|
||||
fn to_single_response(resp: Response) -> Response {
|
||||
|
@ -45,6 +45,7 @@ fn send_command(connection: &mut Telnet, command: &str, skip_ok: bool) -> Result
|
|||
|
||||
read_response(connection, skip_ok, String::new())
|
||||
}
|
||||
|
||||
fn read_response(connection: &mut Telnet, skip_ok: bool, mut buffer: String) -> Result<Response, String> {
|
||||
let (response_str, buffer) = read_response_buffer(connection, &mut buffer)?;
|
||||
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -1,15 +1,17 @@
|
|||
use std::process::exit;
|
||||
|
||||
use telnet::Telnet;
|
||||
|
||||
use crate::cli::Commands;
|
||||
use crate::response::channel::ResponseChannel;
|
||||
use crate::response::client::ResponseClient;
|
||||
|
||||
mod response;
|
||||
mod utils;
|
||||
mod commands;
|
||||
mod parameter;
|
||||
mod cli;
|
||||
|
||||
use std::process::exit;
|
||||
use telnet::Telnet;
|
||||
use crate::cli::Commands;
|
||||
use crate::response::channel::ResponseChannel;
|
||||
use crate::response::client::ResponseClient;
|
||||
|
||||
fn channel_or_exit(channel_res: Result<Option<ResponseChannel>, String>) -> ResponseChannel {
|
||||
channel_res.unwrap_or_else(|err| {
|
||||
println!("Failed to find channel: {}", err);
|
||||
|
@ -33,7 +35,6 @@ fn client_or_exit(client_res: Result<Option<ResponseClient>, String>) -> Respons
|
|||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
let cli = cli::init();
|
||||
|
||||
let connection = Telnet::connect(("127.0.0.1", 25639), 512 * 1024);
|
||||
|
|
|
@ -16,6 +16,7 @@ pub fn parameter_find(params: &Vec<Parameter>, name: &str) -> Option<Parameter>
|
|||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn parameter_list_find(param_lists: &Vec<ParameterList>, name: &str, value: &str, strict: bool) -> Option<ParameterList> {
|
||||
for params in param_lists {
|
||||
if params.iter().any(|param| param.is(name, value, strict)) {
|
||||
|
@ -24,6 +25,7 @@ pub fn parameter_list_find(param_lists: &Vec<ParameterList>, name: &str, value:
|
|||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn parameter_list_find_all(param_lists: &Vec<ParameterList>, name: &str, value: &str, strict: bool) -> Vec<ParameterList> {
|
||||
let mut found = Vec::new();
|
||||
for params in param_lists {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::fmt::{Debug, Display, Formatter};
|
||||
|
||||
use crate::parameter::*;
|
||||
|
||||
pub mod channel;
|
||||
pub mod client;
|
||||
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
use crate::parameter::*;
|
||||
|
||||
pub enum Response {
|
||||
Ok,
|
||||
Data(ParameterList),
|
||||
|
@ -25,8 +26,7 @@ impl TryFrom<String> for Response {
|
|||
response_str = response_str.trim_start_matches("error ");
|
||||
let response_params = parameter_parse(response_str);
|
||||
Err(ResponseError::create_error(&response_params))
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
let mut parameter_lists: Vec<ParameterList> = Vec::new();
|
||||
for response_entry in response_str.split('|') {
|
||||
let response_params = parameter_parse(response_entry);
|
||||
|
@ -39,23 +39,23 @@ impl TryFrom<String> for Response {
|
|||
|
||||
impl Debug for Response {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Response::Ok => {
|
||||
write!(f, "Ok")
|
||||
}
|
||||
Response::Data(params) => {
|
||||
write!(f, "Data:")?;
|
||||
match self {
|
||||
Response::Ok => {
|
||||
write!(f, "Ok")
|
||||
}
|
||||
Response::Data(params) => {
|
||||
write!(f, "Data:")?;
|
||||
write!(f, "{:?};", params)?;
|
||||
Ok(())
|
||||
}
|
||||
Response::DataList(params_list) => {
|
||||
write!(f, "DataList:")?;
|
||||
for params in params_list {
|
||||
write!(f, "{:?};", params)?;
|
||||
Ok(())
|
||||
}
|
||||
Response::DataList(params_list) => {
|
||||
write!(f, "DataList:")?;
|
||||
for params in params_list {
|
||||
write!(f, "{:?};", params)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use crate::parameter::{parameter_find, ParameterList};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use crate::parameter::{parameter_find, ParameterList};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
use std::process::exit;
|
||||
use telnet::Telnet;
|
||||
use std::time::Duration;
|
||||
|
||||
use telnet::Event::TimedOut;
|
||||
use telnet::Telnet;
|
||||
|
||||
use crate::{commands, parameter};
|
||||
use crate::parameter::{parameter_list_find_all, ParameterList};
|
||||
use crate::response::Response;
|
||||
use crate::response::channel::ResponseChannel;
|
||||
use crate::response::client::ResponseClient;
|
||||
use crate::response::Response;
|
||||
|
||||
pub fn skip_welcome(connection: &mut Telnet) {
|
||||
loop {
|
||||
|
@ -31,7 +32,7 @@ pub fn login(connection: &mut Telnet) {
|
|||
});
|
||||
|
||||
match commands::login(connection, &apikey) {
|
||||
Ok(_) => {},
|
||||
Ok(_) => {}
|
||||
Err(msg) => {
|
||||
println!("Failed to authenticate with Teamspeak: {}", msg);
|
||||
exit(1);
|
||||
|
|
Loading…
Reference in a new issue