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 telnet::Telnet;
|
||||||
|
|
||||||
use crate::parameter::{Parameter, ParameterList};
|
use crate::parameter::{Parameter, ParameterList};
|
||||||
use crate::response::channel::ResponseChannel;
|
use crate::response::channel::ResponseChannel;
|
||||||
use crate::response::client::ResponseClient;
|
use crate::response::client::ResponseClient;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use telnet::Telnet;
|
|
||||||
use telnet::Event::Data;
|
use telnet::Event::Data;
|
||||||
use crate::parameter::ParameterList;
|
use telnet::Telnet;
|
||||||
|
|
||||||
|
use crate::parameter::ParameterList;
|
||||||
use crate::response::Response;
|
use crate::response::Response;
|
||||||
|
|
||||||
fn to_single_response(resp: 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())
|
read_response(connection, skip_ok, String::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_response(connection: &mut Telnet, skip_ok: bool, mut buffer: String) -> Result<Response, String> {
|
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)?;
|
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 response;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod parameter;
|
mod parameter;
|
||||||
mod cli;
|
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 {
|
fn channel_or_exit(channel_res: Result<Option<ResponseChannel>, String>) -> ResponseChannel {
|
||||||
channel_res.unwrap_or_else(|err| {
|
channel_res.unwrap_or_else(|err| {
|
||||||
println!("Failed to find channel: {}", err);
|
println!("Failed to find channel: {}", err);
|
||||||
|
@ -33,7 +35,6 @@ fn client_or_exit(client_res: Result<Option<ResponseClient>, String>) -> Respons
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let cli = cli::init();
|
let cli = cli::init();
|
||||||
|
|
||||||
let connection = Telnet::connect(("127.0.0.1", 25639), 512 * 1024);
|
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
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parameter_list_find(param_lists: &Vec<ParameterList>, name: &str, value: &str, strict: bool) -> Option<ParameterList> {
|
pub fn parameter_list_find(param_lists: &Vec<ParameterList>, name: &str, value: &str, strict: bool) -> Option<ParameterList> {
|
||||||
for params in param_lists {
|
for params in param_lists {
|
||||||
if params.iter().any(|param| param.is(name, value, strict)) {
|
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
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parameter_list_find_all(param_lists: &Vec<ParameterList>, name: &str, value: &str, strict: bool) -> Vec<ParameterList> {
|
pub fn parameter_list_find_all(param_lists: &Vec<ParameterList>, name: &str, value: &str, strict: bool) -> Vec<ParameterList> {
|
||||||
let mut found = Vec::new();
|
let mut found = Vec::new();
|
||||||
for params in param_lists {
|
for params in param_lists {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
|
|
||||||
|
use crate::parameter::*;
|
||||||
|
|
||||||
pub mod channel;
|
pub mod channel;
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
|
||||||
use std::fmt::{Debug, Display, Formatter};
|
|
||||||
use crate::parameter::*;
|
|
||||||
|
|
||||||
pub enum Response {
|
pub enum Response {
|
||||||
Ok,
|
Ok,
|
||||||
Data(ParameterList),
|
Data(ParameterList),
|
||||||
|
@ -25,8 +26,7 @@ impl TryFrom<String> for Response {
|
||||||
response_str = response_str.trim_start_matches("error ");
|
response_str = response_str.trim_start_matches("error ");
|
||||||
let response_params = parameter_parse(response_str);
|
let response_params = parameter_parse(response_str);
|
||||||
Err(ResponseError::create_error(&response_params))
|
Err(ResponseError::create_error(&response_params))
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
let mut parameter_lists: Vec<ParameterList> = Vec::new();
|
let mut parameter_lists: Vec<ParameterList> = Vec::new();
|
||||||
for response_entry in response_str.split('|') {
|
for response_entry in response_str.split('|') {
|
||||||
let response_params = parameter_parse(response_entry);
|
let response_params = parameter_parse(response_entry);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
use crate::parameter::{parameter_find, ParameterList};
|
use crate::parameter::{parameter_find, ParameterList};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
use crate::parameter::{parameter_find, ParameterList};
|
use crate::parameter::{parameter_find, ParameterList};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use telnet::Telnet;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use telnet::Event::TimedOut;
|
use telnet::Event::TimedOut;
|
||||||
|
use telnet::Telnet;
|
||||||
|
|
||||||
use crate::{commands, parameter};
|
use crate::{commands, parameter};
|
||||||
use crate::parameter::{parameter_list_find_all, ParameterList};
|
use crate::parameter::{parameter_list_find_all, ParameterList};
|
||||||
use crate::response::Response;
|
|
||||||
use crate::response::channel::ResponseChannel;
|
use crate::response::channel::ResponseChannel;
|
||||||
use crate::response::client::ResponseClient;
|
use crate::response::client::ResponseClient;
|
||||||
|
use crate::response::Response;
|
||||||
|
|
||||||
pub fn skip_welcome(connection: &mut Telnet) {
|
pub fn skip_welcome(connection: &mut Telnet) {
|
||||||
loop {
|
loop {
|
||||||
|
@ -31,7 +32,7 @@ pub fn login(connection: &mut Telnet) {
|
||||||
});
|
});
|
||||||
|
|
||||||
match commands::login(connection, &apikey) {
|
match commands::login(connection, &apikey) {
|
||||||
Ok(_) => {},
|
Ok(_) => {}
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
println!("Failed to authenticate with Teamspeak: {}", msg);
|
println!("Failed to authenticate with Teamspeak: {}", msg);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
Loading…
Reference in a new issue