mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 05:23:20 +00:00
* [nimpretty] fix #10211; fix #10199 * address comments * un-document --backup and set its default to false
This commit is contained in:
committed by
Andreas Rumpf
parent
427435a814
commit
821920aa39
@@ -156,6 +156,8 @@ proc enumToString*(enums: openArray[enum]): string =
|
||||
- `jsondoc` now include a `moduleDescription` field with the module
|
||||
description. `jsondoc0` shows comments as it's own objects as shown in the
|
||||
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
|
||||
- The deprecated `fmod` proc is now unavailable on the VM'.
|
||||
|
||||
@@ -25,11 +25,10 @@ const
|
||||
Usage:
|
||||
nimpretty [options] file.nim
|
||||
Options:
|
||||
--backup:on|off create a backup file before overwritting (default: ON)
|
||||
--output:file set the output file (default: overwrite the .nim file)
|
||||
--indent:N set the number of spaces that is used for indentation
|
||||
--version show the version
|
||||
--help show this help
|
||||
--output:file set the output file (default: overwrite the input file)
|
||||
--indent:N[=2] set the number of spaces that is used for indentation
|
||||
--version show the version
|
||||
--help show this help
|
||||
"""
|
||||
|
||||
proc writeHelp() =
|
||||
@@ -62,7 +61,11 @@ proc prettyPrint(infile, outfile: string, opt: PrettyOptions) =
|
||||
|
||||
proc main =
|
||||
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
|
||||
for kind, key, val in getopt():
|
||||
case kind
|
||||
@@ -79,9 +82,14 @@ proc main =
|
||||
of cmdEnd: assert(false) # cannot happen
|
||||
if infile.len == 0:
|
||||
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:
|
||||
os.copyFile(source=infile, dest=changeFileExt(infile, ".nim.backup"))
|
||||
if outfile.len == 0: outfile = infile
|
||||
let infileBackup = infile & ".backup" # works with .nim or .nims
|
||||
echo "writing backup " & infile & " > " & infileBackup
|
||||
os.copyFile(source = infile, dest = infileBackup)
|
||||
prettyPrint(infile, outfile, opt)
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user