Skip to content

Commit dd49c91

Browse files
committed
Add --verbose option to print one output line per file
Close #227
1 parent 509e5ad commit dd49c91

3 files changed

Lines changed: 90 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
This file documents the changes made to the formatter with each release.
44

5+
## Unreleased
6+
7+
### Added
8+
9+
- Added `--verbose` option to print one line per formatted file (#227)
10+
511
## Release 0.24.0 (2026-07-25)
612

713
### Added

src/cli.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const HELP_FORMATTER: &str = "\
2323
-x, --exclude <PATH> Exclude one file or directory (you can repeat this option multiple times)
2424
--verify-structure Verify formatted output has the same structure as the input
2525
--stdout Write to stdout instead of overwriting files
26+
-v, --verbose Print one status line for each processed file
2627
--use-spaces Use spaces instead of tabs for indentation
2728
--indent-size <NUM> Spaces per indent level (default: 4)
2829
--reorder-code Reorder code to match the style guide
@@ -75,6 +76,8 @@ pub enum Command {
7576
/// If true, prints the formatted output to stdout instead of writing to
7677
/// files.
7778
do_print_to_stdout: bool,
79+
/// If true, prints one status line for each processed file.
80+
use_verbose_output: bool,
7881
/// If true, only checks if the files are formatted, without modifying
7982
/// them. Returns error code ERROR_CODE_NOT_FORMATTED if any of the input
8083
/// files are not formatted.
@@ -130,6 +133,7 @@ pub fn parse_args() -> CliArguments {
130133
let mut input_file_paths: Vec<PathBuf> = Vec::new();
131134
let mut excluded_paths: Vec<PathBuf> = Vec::new();
132135
let mut format_do_print_to_stdout = false;
136+
let mut format_use_verbose_output = false;
133137
let mut format_do_check_formatted_only = false;
134138
let mut format_use_spaces: Option<bool> = None;
135139
let mut format_indent_size: Option<usize> = None;
@@ -197,6 +201,10 @@ pub fn parse_args() -> CliArguments {
197201
require_no_value(assigned_value, "--stdout");
198202
format_do_print_to_stdout = true;
199203
}
204+
"verbose" => {
205+
require_no_value(assigned_value, "--verbose");
206+
format_use_verbose_output = true;
207+
}
200208
"check" => {
201209
require_no_value(assigned_value, "--check");
202210
format_do_check_formatted_only = true;
@@ -376,6 +384,12 @@ pub fn parse_args() -> CliArguments {
376384
}
377385
format_use_verify_structure = true;
378386
}
387+
'v' => {
388+
if matches!(active_command, ActiveCommand::Lint) {
389+
print_error_invalid_argument("unexpected argument '-v'");
390+
}
391+
format_use_verbose_output = true;
392+
}
379393
_ => print_error_invalid_argument(&format!(
380394
"unexpected argument '-{}'",
381395
flag_char
@@ -394,6 +408,7 @@ pub fn parse_args() -> CliArguments {
394408
excluded_paths,
395409
command: Command::Format {
396410
do_print_to_stdout: format_do_print_to_stdout,
411+
use_verbose_output: format_use_verbose_output,
397412
do_check_formatted_only: format_do_check_formatted_only,
398413
use_spaces: format_use_spaces,
399414
indent_size: format_indent_size,

src/main.rs

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
109109

110110
let Command::Format {
111111
do_print_to_stdout,
112+
use_verbose_output,
112113
do_check_formatted_only,
113114
use_spaces,
114115
indent_size,
@@ -187,12 +188,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
187188

188189
let total_files = input_gdscript_files.len();
189190

190-
eprint!(
191-
"Formatting {} file{}...",
192-
total_files,
193-
if total_files == 1 { "" } else { "s" }
194-
);
195-
let _ = io::stdout().flush();
191+
if !use_verbose_output {
192+
eprint!(
193+
"Formatting {} file{}...",
194+
total_files,
195+
if total_files == 1 { "" } else { "s" }
196+
);
197+
let _ = io::stdout().flush();
198+
}
196199

197200
let mut sorted_outputs: Vec<Result<FormatterOutput, String>> =
198201
format_files_parallel(&input_gdscript_files, &config, config_overrides);
@@ -206,6 +209,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
206209
match output {
207210
Ok(output) => {
208211
if do_check_formatted_only {
212+
if use_verbose_output {
213+
eprintln!(
214+
"Checking {}... {}",
215+
output.file_path.display(),
216+
if output.is_formatted {
217+
"OK"
218+
} else {
219+
"needs formatting"
220+
}
221+
);
222+
}
209223
if !output.is_formatted {
210224
all_formatted = false;
211225
unformatted_files.push(output.file_path);
@@ -217,6 +231,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
217231
println!("#--file:{}", output.file_path.display());
218232
}
219233
print!("{}", output.formatted_content);
234+
if use_verbose_output {
235+
eprintln!(
236+
"Formatting {}... {}",
237+
output.file_path.display(),
238+
if output.is_formatted {
239+
"already formatted"
240+
} else {
241+
"done"
242+
}
243+
);
244+
}
220245
} else if !output.is_formatted {
221246
fs::write(&output.file_path, output.formatted_content).map_err(|error| {
222247
format!(
@@ -226,6 +251,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
226251
)
227252
})?;
228253
modified_file_count += 1;
254+
if use_verbose_output {
255+
eprintln!("Formatting {}... done", output.file_path.display());
256+
}
257+
} else if use_verbose_output {
258+
eprintln!(
259+
"Formatting {}... already formatted",
260+
output.file_path.display()
261+
);
229262
}
230263
}
231264
Err(error_msg) => {
@@ -235,35 +268,55 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
235268
}
236269

237270
if do_check_formatted_only {
238-
terminal_clear_line();
271+
if !use_verbose_output {
272+
terminal_clear_line();
273+
}
274+
let summary_prefix = if use_verbose_output { "" } else { "\r" };
239275
if all_formatted {
240-
eprintln!("\rAll {} file(s) are formatted", total_files);
276+
eprintln!(
277+
"{}All {} file(s) are formatted",
278+
summary_prefix, total_files
279+
);
241280
} else {
242-
eprintln!("\rSome files are not formatted");
281+
eprintln!("{}Some files are not formatted", summary_prefix);
243282
for file_path in unformatted_files {
244283
eprintln!("{}", file_path.display());
245284
}
246285
std::process::exit(ERROR_CODE_NOT_FORMATTED);
247286
}
248287
} else if !do_print_to_stdout {
249-
terminal_clear_line();
288+
if !use_verbose_output {
289+
terminal_clear_line();
290+
}
291+
let summary_prefix = if use_verbose_output { "" } else { "\r" };
250292
if total_files == 1 {
251293
if modified_file_count > 0 {
252-
eprintln!("\rFormatted {}", input_gdscript_files[0].display());
294+
eprintln!(
295+
"{}Formatted {}",
296+
summary_prefix,
297+
input_gdscript_files[0].display()
298+
);
253299
} else {
254-
eprintln!("\rAlready formatted: {}", input_gdscript_files[0].display());
300+
eprintln!(
301+
"{}Already formatted: {}",
302+
summary_prefix,
303+
input_gdscript_files[0].display()
304+
);
255305
}
256306
} else {
257307
let already_formatted_count = total_files - modified_file_count;
258308
if modified_file_count > 0 && already_formatted_count > 0 {
259309
eprintln!(
260-
"\rFormatted {} files, {} already formatted",
261-
modified_file_count, already_formatted_count
310+
"{}Formatted {} files, {} already formatted",
311+
summary_prefix, modified_file_count, already_formatted_count
262312
);
263313
} else if modified_file_count > 0 {
264-
eprintln!("\rFormatted {} files", modified_file_count);
314+
eprintln!("{}Formatted {} files", summary_prefix, modified_file_count);
265315
} else {
266-
eprintln!("\rAll {} files already formatted", total_files);
316+
eprintln!(
317+
"{}All {} files already formatted",
318+
summary_prefix, total_files
319+
);
267320
}
268321
}
269322
}

0 commit comments

Comments
 (0)