use geekbar_core::prompt::work_params_handler; use geekbar_core::work::WorksExecutor; use geekbar_core::workflow::WorkflowBuilder; use std::{ sync::{Arc, Mutex}, thread, }; fn main() -> anyhow::Result<()> { let works_executor = Arc::new(Mutex::new(WorksExecutor::default())); let receiver = works_executor.lock().unwrap().receiver().clone(); let executor = works_executor.clone(); let handle = thread::spawn(move || { while let Ok(work_params) = receiver.recv() { if let Some(work_params) = work_params { let work_params = work_params_handler(work_params).unwrap(); executor .lock() .unwrap() .send_params(work_params, None) .unwrap(); } else { std::process::exit(0); } } }); let workflow_1 = WorkflowBuilder::default() .json(include_str!("workflow_1.json")) .build()?; let workflow_2 = WorkflowBuilder::default() .json(include_str!("workflow_2.json")) .build()?; works_executor.lock().unwrap().add_workflow(workflow_1); works_executor.lock().unwrap().add_workflow(workflow_2); let args = std::env::args().collect::>(); let keyword = args.get(1).expect("please input keyword"); let params = args.get(2); works_executor .lock() .unwrap() .trigger(keyword, Some(params))?; handle.join().unwrap(); Ok(()) }