File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change 1
1
use std:: ffi:: OsStr ;
2
2
use std:: path:: Path ;
3
3
4
- use crate :: utils:: run_command_with_output;
4
+ use crate :: utils:: { run_command_with_output, walk_dir } ;
5
5
6
6
fn show_usage ( ) {
7
7
println ! (
@@ -32,5 +32,31 @@ pub fn run() -> Result<(), String> {
32
32
if check { & [ & "cargo" , & "fmt" , & "--check" ] } else { & [ & "cargo" , & "fmt" ] } ;
33
33
34
34
run_command_with_output ( cmd, Some ( Path :: new ( "." ) ) ) ?;
35
- run_command_with_output ( cmd, Some ( Path :: new ( "build_system" ) ) )
35
+ run_command_with_output ( cmd, Some ( Path :: new ( "build_system" ) ) ) ?;
36
+
37
+ run_rustfmt_recursively ( "tests/run" , check)
38
+ }
39
+
40
+ fn run_rustfmt_recursively < P > ( dir : P , check : bool ) -> Result < ( ) , String >
41
+ where
42
+ P : AsRef < Path > ,
43
+ {
44
+ walk_dir (
45
+ dir,
46
+ & mut |dir| run_rustfmt_recursively ( dir, check) ,
47
+ & mut |file_path| {
48
+ if file_path. extension ( ) . filter ( |ext| ext == & OsStr :: new ( "rs" ) ) . is_some ( ) {
49
+ let rustfmt_cmd: & [ & dyn AsRef < OsStr > ] = if check {
50
+ & [ & "rustfmt" , & "--check" , & file_path]
51
+ } else {
52
+ & [ & "rustfmt" , & file_path]
53
+ } ;
54
+
55
+ run_command_with_output ( rustfmt_cmd, Some ( Path :: new ( "." ) ) )
56
+ } else {
57
+ Ok ( ( ) )
58
+ }
59
+ } ,
60
+ true ,
61
+ )
36
62
}
You can’t perform that action at this time.
0 commit comments