Init
This commit is contained in:
commit
13abafae9d
12 changed files with 1095 additions and 0 deletions
src
114
src/main.rs
Normal file
114
src/main.rs
Normal file
|
@ -0,0 +1,114 @@
|
|||
mod response;
|
||||
mod utils;
|
||||
mod commands;
|
||||
mod parameter;
|
||||
mod response_classes;
|
||||
mod cli;
|
||||
|
||||
use std::process::exit;
|
||||
use telnet::Telnet;
|
||||
use crate::cli::Commands;
|
||||
|
||||
fn main() {
|
||||
|
||||
let cli = cli::init();
|
||||
|
||||
let connection = Telnet::connect(("127.0.0.1", 25639), 512 * 1024);
|
||||
if connection.is_err() {
|
||||
println!("Failed to connect to Teamspeak.");
|
||||
exit(1);
|
||||
}
|
||||
let mut connection = connection.unwrap();
|
||||
|
||||
utils::skip_welcome(&mut connection);
|
||||
utils::login(&mut connection);
|
||||
|
||||
// You can check for the existence of subcommands, and if found use their
|
||||
// matches just as you would the top level cmd
|
||||
match &cli {
|
||||
Commands::Channels(args) => {
|
||||
match utils::get_channels(&mut connection, args.spacers) {
|
||||
Ok(channels) => {
|
||||
for channel in channels {
|
||||
println!("{}", channel.channel_name);
|
||||
}
|
||||
}
|
||||
Err(msg) => {
|
||||
println!("Failed to get channels: {}", msg);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Commands::Clients => {
|
||||
match utils::get_clients(&mut connection) {
|
||||
Ok(clients) => {
|
||||
for client in clients {
|
||||
println!("{}", client.client_nickname);
|
||||
}
|
||||
}
|
||||
Err(msg) => {
|
||||
println!("Failed to get clients: {}", msg);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Commands::Fetch(args) => {
|
||||
let client = args.client(&mut connection).unwrap_or_else(|err| {
|
||||
println!("Failed to find client for move: {}", err);
|
||||
exit(1);
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
println!("Failed to find client for move.");
|
||||
exit(1);
|
||||
});
|
||||
|
||||
match utils::fetch_client(&mut connection, &[client]) {
|
||||
Ok(resp) => println!("Successfully fetched client: {}", resp),
|
||||
Err(msg) => {
|
||||
println!("Failed to fetch client: {}", msg);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Commands::Move(args) => {
|
||||
let channel = args.channel(&mut connection).unwrap_or_else(|err| {
|
||||
println!("Failed to find channel for move: {}", err);
|
||||
exit(1);
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
println!("Failed to find channel for move.");
|
||||
exit(1);
|
||||
});
|
||||
|
||||
let client = args.client(&mut connection).unwrap_or_else(|err| {
|
||||
println!("Failed to find client for move: {}", err);
|
||||
exit(1);
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
println!("Failed to find client for move.");
|
||||
exit(1);
|
||||
});
|
||||
|
||||
match utils::move_client(&mut connection, &channel, &[client]) {
|
||||
Ok(resp) => println!("Successfully moved client: {}", resp),
|
||||
Err(msg) => {
|
||||
println!("Failed to move client: {}", msg);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Commands::Update(args) => {
|
||||
match utils::update_client(&mut connection, &args.to_parameter_list()) {
|
||||
Ok(_) => println!("Successfully updated client."),
|
||||
Err(msg) => {
|
||||
println!("Failed to update client: {}", msg);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue