diff --git a/pdl-live-react/src-tauri/src/cli/run.rs b/pdl-live-react/src-tauri/src/cli/run.rs index 3df8671c9..b50210149 100644 --- a/pdl-live-react/src-tauri/src/cli/run.rs +++ b/pdl-live-react/src-tauri/src/cli/run.rs @@ -19,39 +19,10 @@ pub fn run_pdl_program( Path::new(&source_file_path).file_name().unwrap() ); + // async the model pull and pip installs let pull_future = pull_if_needed(&source_file_path); let bin_path_future = pip_install_interpreter_if_needed(app_handle); - let trace_arg = if let Some(arg) = trace_file { - if let serde_json::Value::String(f) = &arg.value { - "--trace=".to_owned() + f - } else { - "".to_owned() - } - } else { - "".to_owned() - }; - - let data_arg = if let Some(arg) = data { - if let serde_json::Value::String(s) = &arg.value { - format!("--data={}", s) - } else { - "".to_owned() - } - } else { - "".to_owned() - }; - - let stream_arg = if let Some(arg) = stream { - if let serde_json::Value::String(s) = &arg.value { - "--stream=".to_owned() + s - } else { - "".to_owned() - } - } else { - "".to_owned() - }; - // wait for any model pulls to finish block_on(pull_future).map_err(|e| match e { LoadError::IO(ee) => tauri::Error::Io(ee), @@ -59,16 +30,30 @@ pub fn run_pdl_program( _ => tauri::Error::FailedToReceiveMessage, })?; + // wait for any pip installs to finish let bin_path = block_on(bin_path_future)?; let mut args = vec![ - source_file_path.as_str(), - trace_arg.as_str(), - data_arg.as_str(), - stream_arg.as_str(), + source_file_path, + dashdash("--trace", trace_file), + dashdash("--data", data), + dashdash("--stream", stream), ]; args.retain(|x| x.chars().count() > 0); cmd(bin_path.join("pdl"), &args).run()?; Ok(()) } + +/// Format `--{opt}={a}` based on whether `a` is given or not +fn dashdash(opt: &str, a: Option<&tauri_plugin_cli::ArgData>) -> String { + if let Some(arg) = a { + if let serde_json::Value::String(s) = &arg.value { + format!("{}={}", opt, s) + } else { + "".to_owned() + } + } else { + "".to_owned() + } +}