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 11use std:: ffi:: OsStr ;
22use std:: path:: Path ;
33
4- use crate :: utils:: run_command_with_output;
4+ use crate :: utils:: { run_command_with_output, walk_dir } ;
55
66fn show_usage ( ) {
77 println ! (
@@ -32,5 +32,31 @@ pub fn run() -> Result<(), String> {
3232 if check { & [ & "cargo" , & "fmt" , & "--check" ] } else { & [ & "cargo" , & "fmt" ] } ;
3333
3434 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+ )
3662}
You can’t perform that action at this time.
0 commit comments