Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 19 additions & 34 deletions pdl-live-react/src-tauri/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,41 @@ 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),
LoadError::Scan(ee) => tauri::Error::Anyhow(ee.into()),
_ => 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()
}
}