mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tools: support v fmt -w -backup file.v
This commit is contained in:
parent
09cc0c7247
commit
fbe54e49f5
@ -26,6 +26,7 @@ struct FormatOptions {
|
||||
is_noerror bool
|
||||
is_verify bool // exit(1) if the file is not vfmt'ed
|
||||
is_worker bool // true *only* in the worker processes. NB: workers can crash.
|
||||
is_backup bool // make a `file.v.bak` copy *before* overwriting a `file.v` in place with `-w`
|
||||
}
|
||||
|
||||
const (
|
||||
@ -53,6 +54,7 @@ fn main() {
|
||||
is_debug: '-debug' in args
|
||||
is_noerror: '-noerror' in args
|
||||
is_verify: '-verify' in args
|
||||
is_backup: '-backup' in args
|
||||
}
|
||||
if term_colors {
|
||||
os.setenv('VCOLORS', 'always', true)
|
||||
@ -249,6 +251,10 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path
|
||||
}
|
||||
if foptions.is_w {
|
||||
if is_formatted_different {
|
||||
if foptions.is_backup {
|
||||
file_bak := '${file}.bak'
|
||||
os.cp(file, file_bak) or {}
|
||||
}
|
||||
os.mv_by_cp(formatted_file_path, file) or { panic(err) }
|
||||
eprintln('Reformatted file: $file')
|
||||
} else {
|
||||
|
@ -18,6 +18,9 @@ Options:
|
||||
-l List files whose formatting differs from vfmt.
|
||||
|
||||
-w Write result to (source) file(s) instead of to stdout.
|
||||
|
||||
-backup In combination with `-w`, copy the original `file.v` to a `file.v.bak` backup,
|
||||
before overwriting the original source file.
|
||||
|
||||
-debug Print the kinds of encountered AST statements/expressions on stderr.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user