| ... | @@ -3792,6 +3792,7 @@ pub const usage_fmt = | ... | @@ -3792,6 +3792,7 @@ pub const usage_fmt = |
| 3792 | \\ --check List non-conforming files and exit with an error | 3792 | \\ --check List non-conforming files and exit with an error |
| 3793 | \\ if the list is non-empty | 3793 | \\ if the list is non-empty |
| 3794 | \\ --ast-check Run zig ast-check on every file | 3794 | \\ --ast-check Run zig ast-check on every file |
| | 3795 | \\ --exclude [file] Exclude file or directory from formatting |
| 3795 | \\ | 3796 | \\ |
| 3796 | \\ | 3797 | \\ |
| 3797 | ; | 3798 | ; |
| ... | @@ -3815,6 +3816,8 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void | ... | @@ -3815,6 +3816,8 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void |
| 3815 | var check_ast_flag: bool = false; | 3816 | var check_ast_flag: bool = false; |
| 3816 | var input_files = ArrayList([]const u8).init(gpa); | 3817 | var input_files = ArrayList([]const u8).init(gpa); |
| 3817 | defer input_files.deinit(); | 3818 | defer input_files.deinit(); |
| | 3819 | var excluded_files = ArrayList([]const u8).init(gpa); |
| | 3820 | defer excluded_files.deinit(); |
| 3818 | | 3821 | |
| 3819 | { | 3822 | { |
| 3820 | var i: usize = 0; | 3823 | var i: usize = 0; |
| ... | @@ -3840,6 +3843,13 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void | ... | @@ -3840,6 +3843,13 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void |
| 3840 | check_flag = true; | 3843 | check_flag = true; |
| 3841 | } else if (mem.eql(u8, arg, "--ast-check")) { | 3844 | } else if (mem.eql(u8, arg, "--ast-check")) { |
| 3842 | check_ast_flag = true; | 3845 | check_ast_flag = true; |
| | 3846 | } else if (mem.eql(u8, arg, "--exclude")) { |
| | 3847 | if (i + 1 >= args.len) { |
| | 3848 | fatal("expected parameter after --exclude", .{}); |
| | 3849 | } |
| | 3850 | i += 1; |
| | 3851 | const next_arg = args[i]; |
| | 3852 | try excluded_files.append(next_arg); |
| 3843 | } else { | 3853 | } else { |
| 3844 | fatal("unrecognized parameter: '{s}'", .{arg}); | 3854 | fatal("unrecognized parameter: '{s}'", .{arg}); |
| 3845 | } | 3855 | } |
| ... | @@ -3940,6 +3950,16 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void | ... | @@ -3940,6 +3950,16 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void |
| 3940 | defer fmt.seen.deinit(); | 3950 | defer fmt.seen.deinit(); |
| 3941 | defer fmt.out_buffer.deinit(); | 3951 | defer fmt.out_buffer.deinit(); |
| 3942 | | 3952 | |
| | 3953 | // Mark any excluded files/directories as already seen, |
| | 3954 | // so that they are skipped later during actual processing |
| | 3955 | for (excluded_files.items) |file_path| { |
| | 3956 | var dir = try fs.cwd().openDir(file_path, .{}); |
| | 3957 | defer dir.close(); |
| | 3958 | |
| | 3959 | const stat = try dir.stat(); |
| | 3960 | try fmt.seen.put(stat.inode, {}); |
| | 3961 | } |
| | 3962 | |
| 3943 | for (input_files.items) |file_path| { | 3963 | for (input_files.items) |file_path| { |
| 3944 | try fmtPath(&fmt, file_path, check_flag, fs.cwd(), file_path); | 3964 | try fmtPath(&fmt, file_path, check_flag, fs.cwd(), file_path); |
| 3945 | } | 3965 | } |