generated from fresh-hduhelper/GoPracticeGin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.nim
74 lines (55 loc) · 1.81 KB
/
util.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os, strutils
proc getFileNameFromAbsPath*(dir: string): string =
result = dir.split("\\")[^1]
{.push inline, used.}
proc getCurModuleContent(pkgName: string): string =
result =
"module " & pkgName & "\n\n" & "go 1.19\n"
proc getCurReadmeContent(dirName: string): string =
result =
"# " & dirName & "\n\n"
var exceptDirs* = @[".git", "misc", ".vscode"]
proc addExceptDir(dirName: string) {.used.} =
exceptDirs.add(dirName)
proc genBatchGoModFile() =
let curDir = getCurrentDir()
for (dirType, path) in walkDir(curDir):
if dirType != pcDir: continue
let dirName = path.split(r"\")[^1]
if dirName in exceptDirs: continue
echo "write in " & dirName
let gomod = open(dirName&"/go.mod", mode = fmWrite)
gomod.write(getCurModuleContent(dirName))
proc genBatchReadmeFile() =
let curDir = getCurrentDir()
for (dirType, path) in walkDir(curDir):
if dirType != pcDir: continue
let dirName = path.split(r"\")[^1]
if dirName in exceptDirs: continue
echo "write in " & dirName
let readme = open(dirName&"/README.md", mode = fmWrite)
readme.write(getCurReadmeContent(dirName))
let chapters = [
"authority", "common-params", "configuration", "custom-server",
"database-sql", "dependency-inject", "middlewire", "project-layer",
"template-mvc", "warming-up"
]
proc `+=`(s: var string, ss: string) =
s = s & " " & ss & " "
proc flat(strs: openArray[string]): string =
for r in strs:
result += r
proc addBatchGoFile2Workspace() =
discard os.execShellCmd("go work init")
discard os.execShellCmd("go work use " & chapters.flat())
proc grading() =
proc checkAuthority(): bool =
discard
{.pop.}
when isMainModule:
when defined(init):
addBatchGoFile2Workspace()
genBatchReadmeFile()
genBatchGoModFile()
when defined(grading):
grading()