vfmt: fix early exit when verifying multiple files; update help (#7611)

pull/7615/head
Lukas Neubert 2020-12-27 14:36:59 +01:00 committed by GitHub
parent 06fdf34214
commit e8b5fa2134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -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
}

View File

@ -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.