From 9b362679695242244a9639cd7a50d86e7382b4bd Mon Sep 17 00:00:00 2001 From: Pol Espinasa Date: Sun, 21 Apr 2024 20:19:04 +0200 Subject: [PATCH] Clean some code and add num argumment control --- server/grouphug-server/src/main.rs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/server/grouphug-server/src/main.rs b/server/grouphug-server/src/main.rs index 675548d..b7e5351 100644 --- a/server/grouphug-server/src/main.rs +++ b/server/grouphug-server/src/main.rs @@ -27,6 +27,11 @@ pub static CONFIG: Lazy = Lazy::new(|| { // Especificar el camí per defecte del fitxer Config.toml let default_path = "Config.toml"; + if args.len() > 2 { + eprintln!("Only 1 argument accepted"); + std::process::exit(1); + } + // Utilitzar l'argument proporcionat si existeix, sinó utilitzar el camí per defecte let config_path = if args.len() > 1 { &args[1] @@ -43,18 +48,6 @@ pub static CONFIG: Lazy = Lazy::new(|| { config }); -/* -pub static CONFIG: Lazy = Lazy::new(|| { - let contents = fs::read_to_string("Config.toml") - .expect("Something went wrong reading the file"); - - let config: Config = toml::from_str(&contents) - .expect("Unable to parse the toml file"); - - config -}); -*/ - // Array with Group list @@ -216,13 +209,7 @@ fn handle_client(mut stream: TcpStream) { fn main() { - - - let args: Vec = env::args().collect(); - //if args.len() != 1 { - // eprintln!("No arguments accepted"); - //} - + // Fromat endpoint data from config file let endpoint: String = format!("{}:{}", &crate::CONFIG.server.ip, &crate::CONFIG.server.port);