* [nimpretty] fix #10211; fix #10199 * address comments * un-document --backup and set its default to false
This commit is contained in:
parent
427435a814
commit
821920aa39
2 changed files with 18 additions and 8 deletions
|
|
@ -156,6 +156,8 @@ proc enumToString*(enums: openArray[enum]): string =
|
||||||
- `jsondoc` now include a `moduleDescription` field with the module
|
- `jsondoc` now include a `moduleDescription` field with the module
|
||||||
description. `jsondoc0` shows comments as it's own objects as shown in the
|
description. `jsondoc0` shows comments as it's own objects as shown in the
|
||||||
documentation.
|
documentation.
|
||||||
|
- `nimpretty`: --backup now defaults to `off` instead of `on` and the flag was
|
||||||
|
un-documented; use `git` instead of relying on backup files.
|
||||||
|
|
||||||
### Compiler changes
|
### Compiler changes
|
||||||
- The deprecated `fmod` proc is now unavailable on the VM'.
|
- The deprecated `fmod` proc is now unavailable on the VM'.
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,10 @@ const
|
||||||
Usage:
|
Usage:
|
||||||
nimpretty [options] file.nim
|
nimpretty [options] file.nim
|
||||||
Options:
|
Options:
|
||||||
--backup:on|off create a backup file before overwritting (default: ON)
|
--output:file set the output file (default: overwrite the input file)
|
||||||
--output:file set the output file (default: overwrite the .nim file)
|
--indent:N[=2] set the number of spaces that is used for indentation
|
||||||
--indent:N set the number of spaces that is used for indentation
|
--version show the version
|
||||||
--version show the version
|
--help show this help
|
||||||
--help show this help
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc writeHelp() =
|
proc writeHelp() =
|
||||||
|
|
@ -62,7 +61,11 @@ proc prettyPrint(infile, outfile: string, opt: PrettyOptions) =
|
||||||
|
|
||||||
proc main =
|
proc main =
|
||||||
var infile, outfile: string
|
var infile, outfile: string
|
||||||
var backup = true
|
var backup = false
|
||||||
|
# when `on`, create a backup file of input in case
|
||||||
|
# `prettyPrint` could over-write it (note that the backup may happen even
|
||||||
|
# if input is not actually over-written, when nimpretty is a noop).
|
||||||
|
# --backup was un-documented (rely on git instead).
|
||||||
var opt: PrettyOptions
|
var opt: PrettyOptions
|
||||||
for kind, key, val in getopt():
|
for kind, key, val in getopt():
|
||||||
case kind
|
case kind
|
||||||
|
|
@ -79,9 +82,14 @@ proc main =
|
||||||
of cmdEnd: assert(false) # cannot happen
|
of cmdEnd: assert(false) # cannot happen
|
||||||
if infile.len == 0:
|
if infile.len == 0:
|
||||||
quit "[Error] no input file."
|
quit "[Error] no input file."
|
||||||
|
if outfile.len == 0:
|
||||||
|
outfile = infile
|
||||||
|
if not existsFile(outfile) or not sameFile(infile, outfile):
|
||||||
|
backup = false # no backup needed since won't be over-written
|
||||||
if backup:
|
if backup:
|
||||||
os.copyFile(source=infile, dest=changeFileExt(infile, ".nim.backup"))
|
let infileBackup = infile & ".backup" # works with .nim or .nims
|
||||||
if outfile.len == 0: outfile = infile
|
echo "writing backup " & infile & " > " & infileBackup
|
||||||
|
os.copyFile(source = infile, dest = infileBackup)
|
||||||
prettyPrint(infile, outfile, opt)
|
prettyPrint(infile, outfile, opt)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue