Skip to content

Commit 021dd83

Browse files
committed
chore: clean up messy rust code in cli::setup
Signed-off-by: Nick Mitchell <[email protected]>
1 parent 7efd58b commit 021dd83

File tree

2 files changed

+38
-48
lines changed

2 files changed

+38
-48
lines changed

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

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,68 +31,58 @@ pub fn cli(app: &mut tauri::App) -> Result<(), Box<dyn ::std::error::Error>> {
3131
let Some(compile_subcommand_matches) = subcommand_matches.matches.subcommand else {
3232
return Err(Box::from("Missing compile subcommand"));
3333
};
34+
let args = compile_subcommand_matches.matches.args;
3435

3536
match compile_subcommand_matches.name.as_str() {
3637
"beeai" => {
37-
// TODO this probably fails if the source is a number??
38-
let Some(ArgData {
39-
value: Value::String(source_file_path),
40-
..
41-
}) = compile_subcommand_matches.matches.args.get("source")
42-
else {
43-
return Err(Box::from("Invalid source file"));
44-
};
45-
let Some(ArgData {
46-
value: Value::String(output_file_path),
47-
..
48-
}) = compile_subcommand_matches.matches.args.get("output")
49-
else {
50-
return Err(Box::from("Invalid output argument"));
51-
};
52-
let Some(ArgData {
53-
value: Value::Bool(debug),
54-
..
55-
}) = compile_subcommand_matches.matches.args.get("debug")
56-
else {
57-
return Err(Box::from("Invalid debug argument"));
58-
};
59-
return compile::beeai::compile(source_file_path, output_file_path, debug);
38+
match (args.get("source"), args.get("output"), args.get("debug")) {
39+
(
40+
// TODO this probably fails if the source is a number??
41+
Some(ArgData {
42+
value: Value::String(source_file_path),
43+
..
44+
}),
45+
Some(ArgData {
46+
value: Value::String(output_file_path),
47+
..
48+
}),
49+
Some(ArgData {
50+
value: Value::Bool(debug),
51+
..
52+
}),
53+
) => compile::beeai::compile(source_file_path, output_file_path, debug),
54+
_ => Err(Box::from("Invalid compile subcommand")),
55+
}
6056
}
61-
_ => {}
57+
_ => Err(Box::from("Unsupported compile command")),
6258
}
6359
}
64-
"run" => {
65-
let Some(source) = subcommand_matches.matches.args.get("source") else {
66-
return Err(Box::from("Missing source file"));
67-
};
68-
let Value::String(source_file_path) = &source.value else {
69-
return Err(Box::from("Invalid source file argument"));
70-
};
71-
return run::run_pdl_program(
60+
"run" => match subcommand_matches.matches.args.get("source") {
61+
Some(ArgData {
62+
value: Value::String(source_file_path),
63+
..
64+
}) => run::run_pdl_program(
7265
source_file_path.clone(),
7366
app.handle().clone(),
7467
subcommand_matches.matches.args.get("trace"),
7568
subcommand_matches.matches.args.get("data"),
7669
subcommand_matches.matches.args.get("stream"),
77-
);
78-
}
79-
"view" => {
80-
let Some(trace) = subcommand_matches.matches.args.get("trace") else {
81-
return Err(Box::from("Missing trace file"));
82-
};
83-
let Value::String(trace_file) = &trace.value else {
84-
return Err(Box::from("Invalid trace file argument"));
85-
};
86-
gui_setup(
70+
),
71+
_ => Err(Box::from("Invalid source file argument")),
72+
},
73+
"view" => match subcommand_matches.matches.args.get("trace") {
74+
Some(ArgData {
75+
value: Value::String(trace_file),
76+
..
77+
}) => gui_setup(
8778
app.handle().clone(),
8879
Path::new("/local")
8980
.join(encode(trace_file).as_ref())
9081
.display()
9182
.to_string(),
92-
)?
93-
}
94-
_ => {}
83+
),
84+
_ => Err(Box::from("Invalid trace file argument")),
85+
},
86+
_ => Err(Box::from("Unsupported command")),
9587
}
96-
97-
Ok(())
9888
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use tauri::WebviewWindowBuilder;
22

3-
pub fn setup(app: tauri::AppHandle, path: String) -> Result<(), tauri::Error> {
3+
pub fn setup(app: tauri::AppHandle, path: String) -> Result<(), Box<dyn ::std::error::Error>> {
44
WebviewWindowBuilder::new(&app, "main", tauri::WebviewUrl::App(path.into()))
55
.title("Prompt Declaration Language")
66
.zoom_hotkeys_enabled(true)

0 commit comments

Comments
 (0)