added a new module and the ability to specify a config file if you want
to.
This commit is contained in:
+31
-7
@@ -1,5 +1,4 @@
|
||||
use clap::Parser;
|
||||
use rcgen::generate_simple_self_signed;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::{env, path::PathBuf, process::exit};
|
||||
use tetanus::funcs::*;
|
||||
@@ -26,14 +25,38 @@ struct Args {
|
||||
|
||||
#[arg(short, long, help = "for testing stuff...")]
|
||||
test: bool,
|
||||
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
help = "The IP address for the server, in server mode it will listen on this IP, in client mode it will add this ip as its first server. Default is 127.0.0.1"
|
||||
)]
|
||||
ip: Option<String>,
|
||||
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
help = "The port for the server, in server mode this will be the port the server listens on, in client mode this will be the default server port it connects to."
|
||||
)]
|
||||
port: Option<String>,
|
||||
|
||||
#[arg(
|
||||
short = 'C',
|
||||
long,
|
||||
help = "Custom Config file. Give the path to a config file to use."
|
||||
)]
|
||||
config: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
println!("checking for server or client config files...");
|
||||
let args = Args::parse();
|
||||
let mut config_path = PathBuf::new();
|
||||
let mut config_path_opt = env::home_dir();
|
||||
if let Some(home_config_path) = config_path_opt.as_mut() {
|
||||
if let Some(given_config_path) = args.config {
|
||||
config_path = given_config_path.clone();
|
||||
} else if let Some(home_config_path) = config_path_opt.as_mut() {
|
||||
println!("made it to home_config_path");
|
||||
home_config_path.push(".config/tetanus");
|
||||
if !home_config_path.exists() {
|
||||
@@ -53,11 +76,8 @@ async fn main() {
|
||||
config_path = home_config_path.clone();
|
||||
}
|
||||
}
|
||||
let args = Args::parse();
|
||||
let mut client_config_path = config_path.clone();
|
||||
client_config_path.push("client.conf");
|
||||
let mut server_config_path = config_path.clone();
|
||||
server_config_path.push("server.conf");
|
||||
if args.client {
|
||||
if !client_config_path.exists() {
|
||||
eprintln!(
|
||||
@@ -76,8 +96,7 @@ async fn main() {
|
||||
println!("entering tui...");
|
||||
let _res = run_tui(appstate, rx).unwrap();
|
||||
} else if args.server {
|
||||
let address = "127.0.0.1:31337".to_string();
|
||||
let names = vec!["127.0.0.1".to_string(), "localhost".to_string()];
|
||||
let mut address = "127.0.0.1:31337".to_string();
|
||||
let mut certificate_path = config_path.clone();
|
||||
certificate_path.push("server");
|
||||
let mut key_path = certificate_path.clone();
|
||||
@@ -85,6 +104,11 @@ async fn main() {
|
||||
key_path.push("key.pem");
|
||||
println!("key paht: {}", key_path.display());
|
||||
println!("cert path: {}", certificate_path.display());
|
||||
if let Some(ip) = args.ip {
|
||||
if let Some(port) = args.port {
|
||||
address = format!("{}:{}", ip.trim(), port.trim());
|
||||
}
|
||||
}
|
||||
let new_server = server::Server {
|
||||
address,
|
||||
clients: Vec::new(),
|
||||
|
||||
Reference in New Issue
Block a user