@@ -53,6 +53,9 @@ pub enum Subcommand {
53
53
Fix {
54
54
paths : Vec < PathBuf > ,
55
55
} ,
56
+ Format {
57
+ check : bool ,
58
+ } ,
56
59
Doc {
57
60
paths : Vec < PathBuf > ,
58
61
} ,
@@ -102,6 +105,7 @@ Subcommands:
102
105
check Compile either the compiler or libraries, using cargo check
103
106
clippy Run clippy
104
107
fix Run cargo fix
108
+ fmt Run rustfmt
105
109
test Build and run some test suites
106
110
bench Build and run some benchmarks
107
111
doc Build documentation
@@ -160,6 +164,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`"
160
164
|| ( s == "check" )
161
165
|| ( s == "clippy" )
162
166
|| ( s == "fix" )
167
+ || ( s == "fmt" )
163
168
|| ( s == "test" )
164
169
|| ( s == "bench" )
165
170
|| ( s == "doc" )
@@ -222,6 +227,9 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`"
222
227
"clean" => {
223
228
opts. optflag ( "" , "all" , "clean all build artifacts" ) ;
224
229
}
230
+ "fmt" => {
231
+ opts. optflag ( "" , "check" , "check formatting instead of applying." ) ;
232
+ }
225
233
_ => { }
226
234
} ;
227
235
@@ -323,6 +331,17 @@ Arguments:
323
331
./x.py fix src/libcore src/libproc_macro" ,
324
332
) ;
325
333
}
334
+ "fmt" => {
335
+ subcommand_help. push_str (
336
+ "\n
337
+ Arguments:
338
+ This subcommand optionally accepts a `--check` flag which succeeds if formatting is correct and
339
+ fails if it is not. For example:
340
+
341
+ ./x.py fmt
342
+ ./x.py fmt --check" ,
343
+ ) ;
344
+ }
326
345
"test" => {
327
346
subcommand_help. push_str (
328
347
"\n
@@ -388,7 +407,7 @@ Arguments:
388
407
389
408
let maybe_rules_help = Builder :: get_help ( & build, subcommand. as_str ( ) ) ;
390
409
extra_help. push_str ( maybe_rules_help. unwrap_or_default ( ) . as_str ( ) ) ;
391
- } else if subcommand. as_str ( ) != "clean" {
410
+ } else if ! ( subcommand. as_str ( ) == "clean" || subcommand . as_str ( ) == "fmt" ) {
392
411
extra_help. push_str (
393
412
format ! (
394
413
"Run `./x.py {} -h -v` to see a list of available paths." ,
@@ -439,6 +458,11 @@ Arguments:
439
458
all : matches. opt_present ( "all" ) ,
440
459
}
441
460
}
461
+ "fmt" => {
462
+ Subcommand :: Format {
463
+ check : matches. opt_present ( "check" ) ,
464
+ }
465
+ }
442
466
"dist" => Subcommand :: Dist { paths } ,
443
467
"install" => Subcommand :: Install { paths } ,
444
468
_ => {
0 commit comments