From e8b5fa2134623e44acdcb635a4fa0a792d0af9f6 Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Sun, 27 Dec 2020 14:36:59 +0100 Subject: [PATCH] vfmt: fix early exit when verifying multiple files; update help (#7611) --- cmd/tools/vfmt.v | 15 +++++++++++---- cmd/v/help/fmt.txt | 4 +++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmd/tools/vfmt.v b/cmd/tools/vfmt.v index 4ff8c16809..8c0579dafa 100644 --- a/cmd/tools/vfmt.v +++ b/cmd/tools/vfmt.v @@ -21,10 +21,11 @@ struct FormatOptions { is_diff bool is_verbose bool is_all bool - is_worker bool is_debug bool is_noerror bool is_verify bool // exit(1) if the file is not vfmt'ed +mut: + is_worker bool } const ( @@ -50,7 +51,7 @@ fn main() { toolexe := os.executable() util.set_vroot_folder(os.dir(os.dir(os.dir(toolexe)))) args := util.join_env_vflags_and_os_args() - foptions := FormatOptions{ + mut foptions := FormatOptions{ is_c: '-c' in args is_l: '-l' in args is_w: '-w' in args @@ -135,7 +136,9 @@ fn main() { wresult := worker_result.output.split(formatted_file_token) formatted_warn_errs := wresult[0] formatted_file_path := wresult[1].trim_right('\n\r') + foptions.is_worker = true foptions.post_process_file(fpath, formatted_file_path) + foptions.is_worker = false if formatted_warn_errs.len > 0 { eprintln(formatted_warn_errs) } @@ -212,7 +215,9 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path x := util.color_compare_files(diff_cmd, file, formatted_file_path) if x.len != 0 { println("$file is not vfmt'ed") - exit(1) + if !foptions.is_worker { + exit(1) + } } return } @@ -228,7 +233,9 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path if foptions.is_c { if is_formatted_different { eprintln('File is not formatted: $file') - exit(2) + if !foptions.is_worker { + exit(2) + } } return } diff --git a/cmd/v/help/fmt.txt b/cmd/v/help/fmt.txt index b79b80d40c..97111df772 100644 --- a/cmd/v/help/fmt.txt +++ b/cmd/v/help/fmt.txt @@ -1,7 +1,9 @@ Usage: v fmt [options] path_to_source.v [path_to_other_source.v] + v fmt [options] path/to/dir [path/to/other_dir] -Formats the given V source files, then prints their formatted source to stdout. +Formats the given V source files or recursively formats all files in the directory, +then prints their formatted source to stdout. Options: -c Check if a file is already formatted. If not, print the filepath and exit with code 2.