@@ -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}
0 commit comments