@@ -102,3 +102,88 @@ def reformat_file(
102102 else :
103103 with atomic_output_file (output , make_parents = make_parents ) as tmp_path :
104104 tmp_path .write_text (result )
105+
106+
107+ def reformat_files (
108+ files : list [str ],
109+ output : str | None = None ,
110+ width : int = 88 ,
111+ inplace : bool = False ,
112+ nobackup : bool = False ,
113+ plaintext : bool = False ,
114+ semantic : bool = False ,
115+ cleanups : bool = True ,
116+ smartquotes : bool = False ,
117+ ellipses : bool = False ,
118+ make_parents : bool = True ,
119+ ) -> None :
120+ """
121+ Reformat multiple files with the same options.
122+
123+ Args:
124+ files: List of file paths to process, or ["-"] for stdin.
125+ output: Output file path (ignored when inplace=True, use "-" for stdout).
126+ width: The width to wrap lines to.
127+ inplace: Whether to write files back to their original paths.
128+ nobackup: Whether to not make backups of original files.
129+ plaintext: Use plaintext instead of Markdown mode wrapping.
130+ semantic: Use semantic line breaks (based on sentences) heuristic.
131+ cleanups: Enable (safe) cleanups for common issues.
132+ smartquotes: Convert straight quotes to typographic quotes.
133+ ellipses: Convert three dots to ellipsis character.
134+ make_parents: Whether to make parent directories if they don't exist.
135+ """
136+ if len (files ) == 1 and files [0 ] == "-" :
137+ # Single stdin case - use original function
138+ reformat_file (
139+ path = files [0 ],
140+ output = output ,
141+ width = width ,
142+ inplace = inplace ,
143+ nobackup = nobackup ,
144+ plaintext = plaintext ,
145+ semantic = semantic ,
146+ cleanups = cleanups ,
147+ smartquotes = smartquotes ,
148+ ellipses = ellipses ,
149+ make_parents = make_parents ,
150+ )
151+ return
152+
153+ # Multiple files case
154+ if not inplace and output and output != "-" :
155+ raise ValueError (
156+ "Cannot specify output file when processing multiple files (use --inplace instead)"
157+ )
158+
159+ for file_path in files :
160+ if inplace :
161+ # Process each file in-place
162+ reformat_file (
163+ path = file_path ,
164+ output = None ,
165+ width = width ,
166+ inplace = True ,
167+ nobackup = nobackup ,
168+ plaintext = plaintext ,
169+ semantic = semantic ,
170+ cleanups = cleanups ,
171+ smartquotes = smartquotes ,
172+ ellipses = ellipses ,
173+ make_parents = make_parents ,
174+ )
175+ else :
176+ # Process each file to stdout
177+ reformat_file (
178+ path = file_path ,
179+ output = "-" ,
180+ width = width ,
181+ inplace = False ,
182+ nobackup = nobackup ,
183+ plaintext = plaintext ,
184+ semantic = semantic ,
185+ cleanups = cleanups ,
186+ smartquotes = smartquotes ,
187+ ellipses = ellipses ,
188+ make_parents = make_parents ,
189+ )
0 commit comments