From d2c0d28683aac94512980fab6bc9e896ace0d694 Mon Sep 17 00:00:00 2001 From: Astatin3 <77305074+Astatin3@users.noreply.github.com> Date: Sun, 4 Aug 2024 13:26:42 -0600 Subject: [PATCH] Finally figure out how to do rust stuff to parse args --- src/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index ef4adbf..13ec66c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,11 +48,15 @@ async fn events(queue: &State>, mut end: Shutdown) -> EventSt } } +fn get_filepath() -> String { + let args = env::args().collect::>(); + return String::from(args[1].as_str()); +} + #[launch] fn rocket() -> _ { - let file_path = Path::new("/tmp/file.md"); - - let file_content = Arc::new(Mutex::new(std::fs::read_to_string(file_path).unwrap())); + + let file_content = Arc::new(Mutex::new(std::fs::read_to_string(get_filepath()).unwrap())); let file_content_clone = Arc::clone(&file_content); let (tx, _) = channel::(1024); @@ -62,9 +66,10 @@ fn rocket() -> _ { std::thread::spawn(move || { let mut watch = Hotwatch::new().unwrap(); - watch.watch(file_path, move |_| { - let content = std::fs::read_to_string(file_path).unwrap(); + watch.watch(get_filepath(), move |_| { + + let content = std::fs::read_to_string(get_filepath()).unwrap(); *file_content_clone.lock().unwrap() = content.clone(); let _ = tx_clone.send(FileChange { content });