mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: fix early exit when verifying multiple files; update help (#7611)
This commit is contained in:
parent
06fdf34214
commit
e8b5fa2134
@ -21,10 +21,11 @@ struct FormatOptions {
|
|||||||
is_diff bool
|
is_diff bool
|
||||||
is_verbose bool
|
is_verbose bool
|
||||||
is_all bool
|
is_all bool
|
||||||
is_worker bool
|
|
||||||
is_debug bool
|
is_debug bool
|
||||||
is_noerror bool
|
is_noerror bool
|
||||||
is_verify bool // exit(1) if the file is not vfmt'ed
|
is_verify bool // exit(1) if the file is not vfmt'ed
|
||||||
|
mut:
|
||||||
|
is_worker bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -50,7 +51,7 @@ fn main() {
|
|||||||
toolexe := os.executable()
|
toolexe := os.executable()
|
||||||
util.set_vroot_folder(os.dir(os.dir(os.dir(toolexe))))
|
util.set_vroot_folder(os.dir(os.dir(os.dir(toolexe))))
|
||||||
args := util.join_env_vflags_and_os_args()
|
args := util.join_env_vflags_and_os_args()
|
||||||
foptions := FormatOptions{
|
mut foptions := FormatOptions{
|
||||||
is_c: '-c' in args
|
is_c: '-c' in args
|
||||||
is_l: '-l' in args
|
is_l: '-l' in args
|
||||||
is_w: '-w' in args
|
is_w: '-w' in args
|
||||||
@ -135,7 +136,9 @@ fn main() {
|
|||||||
wresult := worker_result.output.split(formatted_file_token)
|
wresult := worker_result.output.split(formatted_file_token)
|
||||||
formatted_warn_errs := wresult[0]
|
formatted_warn_errs := wresult[0]
|
||||||
formatted_file_path := wresult[1].trim_right('\n\r')
|
formatted_file_path := wresult[1].trim_right('\n\r')
|
||||||
|
foptions.is_worker = true
|
||||||
foptions.post_process_file(fpath, formatted_file_path)
|
foptions.post_process_file(fpath, formatted_file_path)
|
||||||
|
foptions.is_worker = false
|
||||||
if formatted_warn_errs.len > 0 {
|
if formatted_warn_errs.len > 0 {
|
||||||
eprintln(formatted_warn_errs)
|
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)
|
x := util.color_compare_files(diff_cmd, file, formatted_file_path)
|
||||||
if x.len != 0 {
|
if x.len != 0 {
|
||||||
println("$file is not vfmt'ed")
|
println("$file is not vfmt'ed")
|
||||||
exit(1)
|
if !foptions.is_worker {
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -228,7 +233,9 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path
|
|||||||
if foptions.is_c {
|
if foptions.is_c {
|
||||||
if is_formatted_different {
|
if is_formatted_different {
|
||||||
eprintln('File is not formatted: $file')
|
eprintln('File is not formatted: $file')
|
||||||
exit(2)
|
if !foptions.is_worker {
|
||||||
|
exit(2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
Usage:
|
Usage:
|
||||||
v fmt [options] path_to_source.v [path_to_other_source.v]
|
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:
|
Options:
|
||||||
-c Check if a file is already formatted. If not, print the filepath and exit with code 2.
|
-c Check if a file is already formatted. If not, print the filepath and exit with code 2.
|
||||||
|
Loading…
Reference in New Issue
Block a user