1
+ use clap:: { App , Arg } ;
1
2
use rand:: seq:: SliceRandom ;
2
3
use regex:: Regex ;
3
4
use rodio:: { OutputStream , Sink , Source } ;
@@ -14,31 +15,40 @@ use sys_info::{cpu_num, cpu_speed, hostname, mem_info, os_release, os_type};
14
15
mod test;
15
16
16
17
fn main ( ) {
17
- // Reading command line arguments
18
- let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
19
- if args. len ( ) > 2 {
20
- // Open the script file
21
- match get_file_contents ( args[ 1 ] . clone ( ) ) {
22
- Ok ( code) => {
23
- // Judge execution mode
24
- if args[ 2 ] . contains ( "-d" ) {
25
- let mut executor = Executor :: new ( Mode :: Debug ) ;
26
- executor. evaluate_program ( code) ; // Debug execution
27
- } else {
28
- let mut executor = Executor :: new ( Mode :: Script ) ;
29
- executor. evaluate_program ( code) ; // Script execution
18
+ let matches = App :: new ( "Stack" )
19
+ . version ( "1.11" )
20
+ . author ( "Stack Programming Community" )
21
+ . about ( "The powerful script language designed with a stack oriented approach for efficient execution. " )
22
+ . arg ( Arg :: new ( "script" )
23
+ . index ( 1 )
24
+ . value_name ( "FILE" )
25
+ . help ( "Sets the script file to execution" )
26
+ . takes_value ( true ) )
27
+ . arg ( Arg :: new ( "debug" )
28
+ . short ( 'd' )
29
+ . long ( "debug" )
30
+ . help ( "Enables debug mode" ) )
31
+ . get_matches ( ) ;
32
+
33
+ if let Some ( script) = matches. value_of ( "script" ) {
34
+ if matches. is_present ( "debug" ) {
35
+ let mut stack = Executor :: new ( Mode :: Debug ) ;
36
+ stack. evaluate_program ( match get_file_contents ( script. to_string ( ) ) {
37
+ Ok ( code) => code,
38
+ Err ( err) => {
39
+ println ! ( "Error! {err}" ) ;
40
+ return ;
30
41
}
31
- }
32
- Err ( e) => println ! ( "Error! {e}" ) ,
33
- }
34
- } else if args. len ( ) > 1 {
35
- // Open the script file
36
- match get_file_contents ( args[ 1 ] . clone ( ) ) {
37
- Ok ( code) => {
38
- let mut executor = Executor :: new ( Mode :: Script ) ;
39
- executor. evaluate_program ( code) ; // Default is script execution
40
- }
41
- Err ( e) => println ! ( "Error! {e}" ) ,
42
+ } )
43
+ } else {
44
+ let mut stack = Executor :: new ( Mode :: Script ) ;
45
+ stack. evaluate_program ( match get_file_contents ( script. to_string ( ) ) {
46
+ Ok ( code) => code,
47
+ Err ( err) => {
48
+ println ! ( "Error! {err}" ) ;
49
+ return ;
50
+ }
51
+ } )
42
52
}
43
53
} else {
44
54
// Show a title
0 commit comments