Skip to content

Commit 2ea1b1e

Browse files
committed
feat: support for --data and --data-file in rust interpreter
Signed-off-by: Nick Mitchell <[email protected]>
1 parent 61ef436 commit 2ea1b1e

File tree

5 files changed

+235
-130
lines changed

5 files changed

+235
-130
lines changed

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use urlencoding::encode;
55

66
use crate::compile;
77
use crate::gui::new_window;
8-
use crate::pdl::interpreter::run_file_sync as run;
8+
use crate::pdl::interpreter::{load_scope, run_file_sync, RunOptions};
99

1010
#[cfg(desktop)]
1111
pub fn setup(app: &mut tauri::App) -> Result<bool, Box<dyn ::std::error::Error>> {
@@ -49,26 +49,31 @@ pub fn setup(app: &mut tauri::App) -> Result<bool, Box<dyn ::std::error::Error>>
4949
_ => Err(Box::from("Unsupported compile command")),
5050
}
5151
}
52-
"run" => run(
52+
"run" => run_file_sync(
5353
subcommand_args
5454
.get("source")
5555
.and_then(|a| a.value.as_str())
5656
.expect("valid positional source arg"),
57-
subcommand_args.get("trace").and_then(|a| a.value.as_str()),
58-
subcommand_args.get("data").and_then(|a| a.value.as_str()),
59-
subcommand_args
60-
.get("data-file")
61-
.and_then(|a| a.value.as_str()),
62-
subcommand_args
63-
.get("debug")
64-
.and_then(|a| a.value.as_bool())
65-
.or(Some(false))
66-
== Some(true),
67-
subcommand_args
68-
.get("no-stream")
69-
.and_then(|a| a.value.as_bool())
70-
.or(Some(false))
71-
== Some(false),
57+
RunOptions {
58+
trace: subcommand_args.get("trace").and_then(|a| a.value.as_str()),
59+
debug: subcommand_args
60+
.get("debug")
61+
.and_then(|a| a.value.as_bool())
62+
.or(Some(false))
63+
== Some(true),
64+
stream: subcommand_args
65+
.get("no-stream")
66+
.and_then(|a| a.value.as_bool())
67+
.or(Some(false))
68+
== Some(false),
69+
},
70+
load_scope(
71+
subcommand_args.get("data").and_then(|a| a.value.as_str()),
72+
subcommand_args
73+
.get("data-file")
74+
.and_then(|a| a.value.as_str()),
75+
None,
76+
)?,
7277
)
7378
.and_then(|_trace| Ok(true)),
7479
"view" => new_window(

pdl-live-react/src-tauri/src/commands/interpreter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::pdl::interpreter::{pretty_print, run_string};
22

33
#[tauri::command]
4-
pub async fn run_pdl_program(program: String, debug: bool) -> Result<String, String> {
5-
let (_, messages, _) = run_string(&program, debug)
4+
pub async fn run_pdl_program(program: String) -> Result<String, String> {
5+
let (_, messages, _) = run_string(&program, Default::default(), Default::default())
66
.await
77
.map_err(|err| err.to_string())?;
88

0 commit comments

Comments
 (0)