-
Notifications
You must be signed in to change notification settings - Fork 36
/
nicoboot.nim
46 lines (40 loc) · 1.4 KB
/
nicoboot.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
# tool to set up a new nico project
import os
import osproc
import parseopt
var params = initOptParser(commandLineParams(), shortNoVal = {'f'})
var targetPath: string = ""
var orgName: string = ""
var appName: string = ""
var overwrite = false
var arg = 0
for kind, key, val in getOpt(params):
case kind:
of cmdArgument:
if arg == 0:
orgName = key
elif arg == 1:
appName = key
elif arg == 2:
targetPath = key
arg.inc
of cmdLongOption, cmdShortOption:
case key:
of "f": overwrite = true
of cmdEnd:
assert(false)
if targetPath == "":
echo "nicoboot [-f] orgName appName projectPath"
quit(1)
# create a new project
let sourcePath = joinPath(getAppDir(), "exampleApp")
if overwrite == false and (dirExists(targetPath) or fileExists(targetPath) or symlinkExists(targetPath)):
echo "not overwriting existing path: ", targetPath, " use -f to overwrite"
quit(1)
echo "copying ", sourcePath, " to ", targetPath
copyDir(sourcePath, targetPath)
# search and replace
moveFile(joinPath(targetPath, "exampleApp.nimble"), joinPath(targetPath, appName & ".nimble"))
echo execProcess("nimgrep", "", ["-!","exampleApp",appName,"-r",targetPath], nil, {poUsePath, poStdErrToStdOut})
echo execProcess("nimgrep", "", ["-!","exampleOrg",orgName,"-r",targetPath], nil, {poUsePath, poStdErrToStdOut})
echo "nico project ", appName, " created in ", targetPath