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_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,8 +215,10 @@ 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")
|
||||
if !foptions.is_worker {
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
fc := os.read_file(file) or {
|
||||
@ -228,8 +233,10 @@ 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')
|
||||
if !foptions.is_worker {
|
||||
exit(2)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if foptions.is_l {
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user