@@ -15,6 +15,10 @@ enum Command {
1515 Watch ,
1616 /// Clean the build artifacts
1717 Clean ,
18+ /// Format the code
19+ Format ,
20+ /// Dump
21+ Dump ,
1822}
1923
2024/// Rewatch is an alternative build system for the Rescript Compiler bsb (which uses Ninja internally). It strives
@@ -23,11 +27,12 @@ enum Command {
2327#[ derive( Parser , Debug ) ]
2428#[ command( version) ]
2529struct Args {
26- #[ arg( value_enum) ]
27- command : Option < Command > ,
30+ #[ arg( value_enum, default_value_t = Command :: Build ) ]
31+ command : Command ,
2832
2933 /// The relative path to where the main rescript.json resides. IE - the root of your project.
30- folder : Option < String > ,
34+ #[ arg( default_value = "." ) ]
35+ folder : String ,
3136
3237 /// Filter allows for a regex to be supplied which will filter the files to be compiled. For
3338 /// instance, to filter out test files for compilation while doing feature work.
@@ -79,10 +84,22 @@ struct Args {
7984 /// A custom path to bsc
8085 #[ arg( long) ]
8186 bsc_path : Option < String > ,
87+
88+ /// Use the legacy build system.
89+ ///
90+ /// After this flag is encountered, the rest of the command line arguments are passed to the legacy build system.
91+ #[ arg( long, allow_hyphen_values = true , num_args = 0 ..) ]
92+ legacy : Option < Vec < String > > ,
8293}
8394
8495fn main ( ) -> Result < ( ) > {
8596 let args = Args :: parse ( ) ;
97+
98+ if let Some ( legacy_args) = args. legacy {
99+ let code = build:: pass_through_legacy ( legacy_args) ;
100+ std:: process:: exit ( code) ;
101+ }
102+
86103 let log_level_filter = args. verbose . log_level_filter ( ) ;
87104
88105 env_logger:: Builder :: new ( )
@@ -91,8 +108,6 @@ fn main() -> Result<()> {
91108 . target ( env_logger:: fmt:: Target :: Stdout )
92109 . init ( ) ;
93110
94- let command = args. command . unwrap_or ( Command :: Build ) ;
95- let folder = args. folder . unwrap_or ( "." . to_string ( ) ) ;
96111 let filter = args
97112 . filter
98113 . map ( |filter| Regex :: new ( filter. as_ref ( ) ) . expect ( "Could not parse regex" ) ) ;
@@ -112,17 +127,17 @@ fn main() -> Result<()> {
112127 // level, we should never show that.
113128 let show_progress = log_level_filter == LevelFilter :: Info ;
114129
115- match lock:: get ( & folder) {
130+ match lock:: get ( & args . folder ) {
116131 lock:: Lock :: Error ( ref e) => {
117132 println ! ( "Could not start Rewatch: {e}" ) ;
118133 std:: process:: exit ( 1 )
119134 }
120- lock:: Lock :: Aquired ( _) => match command {
121- Command :: Clean => build:: clean:: clean ( & folder, show_progress, args. bsc_path , args. dev ) ,
135+ lock:: Lock :: Aquired ( _) => match args . command {
136+ Command :: Clean => build:: clean:: clean ( & args . folder , show_progress, args. bsc_path , args. dev ) ,
122137 Command :: Build => {
123138 match build:: build (
124139 & filter,
125- & folder,
140+ & args . folder ,
126141 show_progress,
127142 args. no_timing ,
128143 args. create_sourcedirs ,
@@ -145,7 +160,7 @@ fn main() -> Result<()> {
145160 watcher:: start (
146161 & filter,
147162 show_progress,
148- & folder,
163+ & args . folder ,
149164 args. after_build ,
150165 args. create_sourcedirs ,
151166 args. dev ,
@@ -154,6 +169,12 @@ fn main() -> Result<()> {
154169
155170 Ok ( ( ) )
156171 }
172+ Command :: Format => {
173+ todo ! ( "Format not implemented yet" ) ;
174+ }
175+ Command :: Dump => {
176+ todo ! ( "Dump not implemented yet" ) ;
177+ }
157178 } ,
158179 }
159180}
0 commit comments