Add --root-dir option

This commit is contained in:
g1n 2021-07-17 13:47:48 +00:00
parent 19d58583c0
commit 3a4a6d404b
1 changed files with 5 additions and 5 deletions

View File

@ -12,6 +12,7 @@ fn main() {
let mut verbose = false;
let mut host = "localhost".to_string();
let mut port = 3000; // TODO: change to 300
let mut root_dir = "/var/spartan/".to_string();
// Arguments
{
let mut ap = ArgumentParser::new();
@ -25,9 +26,9 @@ fn main() {
ap.refer(&mut port)
.add_option(&["-p", "--port"], Store,
"Port");
/*ap.refer(&mut root_dir)
ap.refer(&mut root_dir)
.add_option(&["-d", "--root-dir"], Store,
"Root directory");*/
"Root directory");
ap.parse_args_or_exit();
}
if verbose {
@ -37,13 +38,12 @@ fn main() {
for stream in listener.incoming() {
let stream = stream.unwrap();
handle_connection(stream);
handle_connection(stream, root_dir.to_string());
}
}
fn handle_connection(mut stream: TcpStream) {
fn handle_connection(mut stream: TcpStream, root_dir: String) {
let mut buffer = [0; 1024];
let root_dir = "/home/g1n/public_spartan/";
stream.read(&mut buffer).unwrap();
println!("{}", String::from_utf8_lossy(&buffer[..]));