improved nim fmt
This commit is contained in:
parent
bd9234012f
commit
d2b0dad988
1 changed files with 13 additions and 12 deletions
|
@ -26,24 +26,25 @@ let
|
||||||
(_, pkgName) = root.splitPath()
|
(_, pkgName) = root.splitPath()
|
||||||
srcFile = root / "src" / (pkgName & ".nim")
|
srcFile = root / "src" / (pkgName & ".nim")
|
||||||
|
|
||||||
|
proc projectGorgeEx(cmd: string): string =
|
||||||
|
## cd into the project before running any commands
|
||||||
|
let (output, code) = gorgeEx(fmt"cd {getCurrentDir()} && {cmd}")
|
||||||
|
if code != 0: echo "ERROR executing: " & cmd; quit 1
|
||||||
|
return output
|
||||||
|
|
||||||
task fmt, "Run nimpretty on all git-managed .nim files in the current repo":
|
task fmt, "Run nimpretty on all git-managed .nim files in the current repo":
|
||||||
## Usage: nim fmt
|
## Usage: nim fmt
|
||||||
for file in walkDirRec(root, {pcFile, pcDir}):
|
let srcFiles = projectGorgeEx(r"nimgrep --filenames -r '^src/.*\.nim$' --noColor").split("\n")[0..^2]
|
||||||
if file.splitFile().ext == ".nim":
|
for file in srcFiles:
|
||||||
let
|
let cmd = "nimpretty $1" % [file]
|
||||||
# https://github.com/nim-lang/Nim/issues/6262#issuecomment-454983572
|
echo "Running $1 .." % [cmd]
|
||||||
# https://stackoverflow.com/a/2406813/1219634
|
exec(cmd)
|
||||||
fileIsGitManaged = gorgeEx("cd $1 && git ls-files --error-unmatch $2" % [getCurrentDir(), file]).exitCode == 0
|
|
||||||
# ^^^^^-- That "cd" is required.
|
|
||||||
if fileIsGitManaged:
|
|
||||||
let
|
|
||||||
cmd = "nimpretty $1" % [file]
|
|
||||||
echo "Running $1 .." % [cmd]
|
|
||||||
exec(cmd)
|
|
||||||
setCommand("nop")
|
setCommand("nop")
|
||||||
|
|
||||||
task i, "install package":
|
task i, "install package":
|
||||||
exec "nimble install"
|
exec "nimble install"
|
||||||
|
setCommand("nop")
|
||||||
|
|
||||||
|
|
||||||
task lexidInc, "bump lexigraphic id":
|
task lexidInc, "bump lexigraphic id":
|
||||||
|
|
Loading…
Reference in a new issue