1- use std:: ffi:: OsString ;
1+ use std:: { ffi:: OsString , ops :: Deref } ;
22
33use clap:: { Args , Parser , Subcommand } ;
44use clap_verbosity_flag:: InfoLevel ;
@@ -24,23 +24,29 @@ pub struct Cli {
2424 #[ command( subcommand) ]
2525 pub command : Option < Command > ,
2626
27+ #[ command( flatten) ]
28+ pub build_args : BuildArgs ,
29+ }
30+
31+ #[ derive( Args , Debug , Clone ) ]
32+ pub struct FolderArg {
2733 /// The relative path to where the main rescript.json resides. IE - the root of your project.
2834 #[ arg( default_value = "." ) ]
2935 pub folder : String ,
30-
31- #[ command( flatten) ]
32- pub build_args : BuildArgs ,
3336}
3437
3538#[ derive( Args , Debug , Clone ) ]
36- pub struct BuildArgs {
39+ pub struct FilterArg {
3740 /// Filter files by regex
3841 ///
3942 /// Filter allows for a regex to be supplied which will filter the files to be compiled. For
4043 /// instance, to filter out test files for compilation while doing feature work.
4144 #[ arg( short, long) ]
4245 pub filter : Option < String > ,
46+ }
4347
48+ #[ derive( Args , Debug , Clone ) ]
49+ pub struct AfterBuildArg {
4450 /// Action after build
4551 ///
4652 /// This allows one to pass an additional command to the watcher, which allows it to run when
@@ -49,14 +55,20 @@ pub struct BuildArgs {
4955 /// color as well
5056 #[ arg( short, long) ]
5157 pub after_build : Option < String > ,
58+ }
5259
60+ #[ derive( Args , Debug , Clone , Copy ) ]
61+ pub struct CreateSourceDirsArg {
5362 /// Create source_dirs.json
5463 ///
5564 /// This creates a source_dirs.json file at the root of the monorepo, which is needed when you
5665 /// want to use Reanalyze
5766 #[ arg( short, long, default_value_t = false , num_args = 0 ..=1 ) ]
5867 pub create_sourcedirs : bool ,
68+ }
5969
70+ #[ derive( Args , Debug , Clone , Copy ) ]
71+ pub struct DevArg {
6072 /// Build development dependencies
6173 ///
6274 /// This is the flag to also compile development dependencies
@@ -65,61 +77,72 @@ pub struct BuildArgs {
6577 /// _all_ packages
6678 #[ arg( long, default_value_t = false , num_args = 0 ..=1 ) ]
6779 pub dev : bool ,
80+ }
6881
69- /// Disable timing on the output
70- #[ arg( short, long, default_value_t = false , num_args = 0 ..=1 ) ]
71- pub no_timing : bool ,
82+ #[ derive( Args , Debug , Clone ) ]
83+ pub struct BscPathArg {
84+ /// Custom path to bsc
85+ #[ arg( long) ]
86+ pub bsc_path : Option < String > ,
87+ }
7288
89+ #[ derive( Args , Debug , Clone , Copy ) ]
90+ pub struct SnapshotOutputArg {
7391 /// simple output for snapshot testing
7492 #[ arg( short, long, default_value = "false" , num_args = 0 ..=1 ) ]
7593 pub snapshot_output : bool ,
94+ }
7695
77- /// Path to bsc
78- #[ arg( long) ]
79- pub bsc_path : Option < String > ,
96+ #[ derive( Args , Debug , Clone ) ]
97+ pub struct BuildArgs {
98+ #[ command( flatten) ]
99+ pub folder : FolderArg ,
100+
101+ #[ command( flatten) ]
102+ pub filter : FilterArg ,
103+
104+ #[ command( flatten) ]
105+ pub after_build : AfterBuildArg ,
106+
107+ #[ command( flatten) ]
108+ pub create_sourcedirs : CreateSourceDirsArg ,
109+
110+ #[ command( flatten) ]
111+ pub dev : DevArg ,
112+
113+ /// Disable timing on the output
114+ #[ arg( short, long, default_value_t = false , num_args = 0 ..=1 ) ]
115+ pub no_timing : bool ,
116+
117+ #[ command( flatten) ]
118+ pub snapshot_output : SnapshotOutputArg ,
119+
120+ #[ command( flatten) ]
121+ pub bsc_path : BscPathArg ,
80122}
81123
82124#[ derive( Args , Clone , Debug ) ]
83125pub struct WatchArgs {
84- /// Filter files by regex
85- ///
86- /// Filter allows for a regex to be supplied which will filter the files to be compiled. For
87- /// instance, to filter out test files for compilation while doing feature work.
88- #[ arg( short, long) ]
89- pub filter : Option < String > ,
126+ #[ command( flatten) ]
127+ pub folder : FolderArg ,
90128
91- /// Action after build
92- ///
93- /// This allows one to pass an additional command to the watcher, which allows it to run when
94- /// finished. For instance, to play a sound when done compiling, or to run a test suite.
95- /// NOTE - You may need to add '--color=always' to your subcommand in case you want to output
96- /// color as well
97- #[ arg( short, long) ]
98- pub after_build : Option < String > ,
129+ #[ command( flatten) ]
130+ pub filter : FilterArg ,
99131
100- /// Create source_dirs.json
101- ///
102- /// This creates a source_dirs.json file at the root of the monorepo, which is needed when you
103- /// want to use Reanalyze
104- #[ arg( short, long, default_value_t = false , num_args = 0 ..=1 ) ]
105- pub create_sourcedirs : bool ,
132+ #[ command( flatten) ]
133+ pub after_build : AfterBuildArg ,
106134
107- /// Build development dependencies
108- ///
109- /// This is the flag to also compile development dependencies
110- /// It's important to know that we currently do not discern between project src, and
111- /// dependencies. So enabling this flag will enable building _all_ development dependencies of
112- /// _all_ packages
113- #[ arg( long, default_value_t = false , num_args = 0 ..=1 ) ]
114- pub dev : bool ,
135+ #[ command( flatten) ]
136+ pub create_sourcedirs : CreateSourceDirsArg ,
115137
116- /// simple output for snapshot testing
117- #[ arg( short, long, default_value = "false" , num_args = 0 ..=1 ) ]
118- pub snapshot_output : bool ,
138+ #[ command( flatten) ]
139+ pub dev : DevArg ,
119140
120- /// Path to bsc
121- #[ arg( long) ]
122- pub bsc_path : Option < String > ,
141+ #[ command( flatten) ]
142+ pub snapshot_output : SnapshotOutputArg ,
143+
144+ #[ command( flatten) ]
145+ pub bsc_path : BscPathArg ,
123146}
124147
125148#[ derive( Subcommand , Clone , Debug ) ]
@@ -130,13 +153,14 @@ pub enum Command {
130153 Watch ( WatchArgs ) ,
131154 /// Clean the build artifacts
132155 Clean {
133- /// Path to bsc
134- #[ arg( long) ]
135- bsc_path : Option < String > ,
156+ #[ command( flatten) ]
157+ folder : FolderArg ,
158+
159+ #[ command( flatten) ]
160+ bsc_path : BscPathArg ,
136161
137- /// simple output for snapshot testing
138- #[ arg( short, long, default_value = "false" , num_args = 0 ..=1 ) ]
139- snapshot_output : bool ,
162+ #[ command( flatten) ]
163+ snapshot_output : SnapshotOutputArg ,
140164 } ,
141165 /// Alias to `legacy format`.
142166 #[ command( disable_help_flag = true ) ]
@@ -156,23 +180,78 @@ pub enum Command {
156180 #[ command( ) ]
157181 path : String ,
158182
159- #[ arg ( long , default_value_t = false , num_args = 0 ..= 1 ) ]
160- dev : bool ,
183+ #[ command ( flatten ) ]
184+ dev : DevArg ,
161185
162186 /// To be used in conjunction with compiler_args
163187 #[ arg( long) ]
164188 rescript_version : Option < String > ,
165189
166- /// A custom path to bsc
167- #[ arg( long) ]
168- bsc_path : Option < String > ,
190+ #[ command( flatten) ]
191+ bsc_path : BscPathArg ,
169192 } ,
170193 /// Use the legacy build system.
171194 ///
172195 /// After this command is encountered, the rest of the arguments are passed to the legacy build system.
173- #[ command( disable_help_flag = true ) ]
196+ #[ command( disable_help_flag = true , external_subcommand = true ) ]
174197 Legacy {
175198 #[ arg( allow_hyphen_values = true , num_args = 0 ..) ]
176199 legacy_args : Vec < OsString > ,
177200 } ,
178201}
202+
203+ impl Deref for FolderArg {
204+ type Target = str ;
205+
206+ fn deref ( & self ) -> & Self :: Target {
207+ & self . folder
208+ }
209+ }
210+
211+ impl Deref for FilterArg {
212+ type Target = Option < String > ;
213+
214+ fn deref ( & self ) -> & Self :: Target {
215+ & self . filter
216+ }
217+ }
218+
219+ impl Deref for AfterBuildArg {
220+ type Target = Option < String > ;
221+
222+ fn deref ( & self ) -> & Self :: Target {
223+ & self . after_build
224+ }
225+ }
226+
227+ impl Deref for CreateSourceDirsArg {
228+ type Target = bool ;
229+
230+ fn deref ( & self ) -> & Self :: Target {
231+ & self . create_sourcedirs
232+ }
233+ }
234+
235+ impl Deref for DevArg {
236+ type Target = bool ;
237+
238+ fn deref ( & self ) -> & Self :: Target {
239+ & self . dev
240+ }
241+ }
242+
243+ impl Deref for BscPathArg {
244+ type Target = Option < String > ;
245+
246+ fn deref ( & self ) -> & Self :: Target {
247+ & self . bsc_path
248+ }
249+ }
250+
251+ impl Deref for SnapshotOutputArg {
252+ type Target = bool ;
253+
254+ fn deref ( & self ) -> & Self :: Target {
255+ & self . snapshot_output
256+ }
257+ }
0 commit comments