Skip to content

Commit 131ba5d

Browse files
committed
chore: rust code cleanup of run.rs
Signed-off-by: Nick Mitchell <[email protected]>
1 parent 82ccd75 commit 131ba5d

File tree

1 file changed

+19
-34
lines changed
  • pdl-live-react/src-tauri/src/cli

1 file changed

+19
-34
lines changed

pdl-live-react/src-tauri/src/cli/run.rs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,56 +19,41 @@ pub fn run_pdl_program(
1919
Path::new(&source_file_path).file_name().unwrap()
2020
);
2121

22+
// async the model pull and pip installs
2223
let pull_future = pull_if_needed(&source_file_path);
2324
let bin_path_future = pip_install_interpreter_if_needed(app_handle);
2425

25-
let trace_arg = if let Some(arg) = trace_file {
26-
if let serde_json::Value::String(f) = &arg.value {
27-
"--trace=".to_owned() + f
28-
} else {
29-
"".to_owned()
30-
}
31-
} else {
32-
"".to_owned()
33-
};
34-
35-
let data_arg = if let Some(arg) = data {
36-
if let serde_json::Value::String(s) = &arg.value {
37-
format!("--data={}", s)
38-
} else {
39-
"".to_owned()
40-
}
41-
} else {
42-
"".to_owned()
43-
};
44-
45-
let stream_arg = if let Some(arg) = stream {
46-
if let serde_json::Value::String(s) = &arg.value {
47-
"--stream=".to_owned() + s
48-
} else {
49-
"".to_owned()
50-
}
51-
} else {
52-
"".to_owned()
53-
};
54-
5526
// wait for any model pulls to finish
5627
block_on(pull_future).map_err(|e| match e {
5728
LoadError::IO(ee) => tauri::Error::Io(ee),
5829
LoadError::Scan(ee) => tauri::Error::Anyhow(ee.into()),
5930
_ => tauri::Error::FailedToReceiveMessage,
6031
})?;
6132

33+
// wait for any pip installs to finish
6234
let bin_path = block_on(bin_path_future)?;
6335

6436
let mut args = vec![
65-
source_file_path.as_str(),
66-
trace_arg.as_str(),
67-
data_arg.as_str(),
68-
stream_arg.as_str(),
37+
source_file_path,
38+
dashdash("--trace", trace_file),
39+
dashdash("--data", data),
40+
dashdash("--stream", stream),
6941
];
7042
args.retain(|x| x.chars().count() > 0);
7143
cmd(bin_path.join("pdl"), &args).run()?;
7244

7345
Ok(())
7446
}
47+
48+
/// Format `--{opt}={a}` based on whether `a` is given or not
49+
fn dashdash(opt: &str, a: Option<&tauri_plugin_cli::ArgData>) -> String {
50+
if let Some(arg) = a {
51+
if let serde_json::Value::String(s) = &arg.value {
52+
format!("{}={}", opt, s)
53+
} else {
54+
"".to_owned()
55+
}
56+
} else {
57+
"".to_owned()
58+
}
59+
}

0 commit comments

Comments
 (0)