Abstract parsing of the actions.
This commit is contained in:
parent
207f1bd63c
commit
1edfb80c85
1 changed files with 76 additions and 56 deletions
132
src/nimble.nim
132
src/nimble.nim
|
|
@ -161,6 +161,61 @@ proc renameBabelToNimble(options: Options) {.deprecated.} =
|
||||||
removeDir(babelDir)
|
removeDir(babelDir)
|
||||||
removeFile(nimbleDir / "babeldata.json")
|
removeFile(nimbleDir / "babeldata.json")
|
||||||
|
|
||||||
|
proc parseActionType(action: string): ActionType =
|
||||||
|
case action.normalize()
|
||||||
|
of "install", "path":
|
||||||
|
case action.normalize()
|
||||||
|
of "install":
|
||||||
|
result = actionInstall
|
||||||
|
of "path":
|
||||||
|
result = actionPath
|
||||||
|
else:
|
||||||
|
discard
|
||||||
|
of "build":
|
||||||
|
result = actionBuild
|
||||||
|
of "c", "compile", "js", "cpp", "cc":
|
||||||
|
result = actionCompile
|
||||||
|
of "init":
|
||||||
|
result = actionInit
|
||||||
|
of "dump":
|
||||||
|
result = actionDump
|
||||||
|
of "update":
|
||||||
|
result = actionUpdate
|
||||||
|
of "search":
|
||||||
|
result = actionSearch
|
||||||
|
of "list":
|
||||||
|
result = actionList
|
||||||
|
of "uninstall", "remove", "delete", "del", "rm":
|
||||||
|
result = actionUninstall
|
||||||
|
of "publish":
|
||||||
|
result = actionPublish
|
||||||
|
else:
|
||||||
|
result = actionCustom
|
||||||
|
|
||||||
|
proc initAction(options: var Options, key: string) =
|
||||||
|
## Intialises `options.actions` fields based on `options.actions.typ` and
|
||||||
|
## `key`.
|
||||||
|
let keyNorm = key.normalize()
|
||||||
|
case options.action.typ
|
||||||
|
of actionInstall, actionPath:
|
||||||
|
options.action.packages = @[]
|
||||||
|
of actionCompile:
|
||||||
|
options.action.compileOptions = @[]
|
||||||
|
options.action.file = ""
|
||||||
|
if keyNorm == "c" or keyNorm == "compile": options.action.backend = ""
|
||||||
|
else: options.action.backend = keyNorm
|
||||||
|
of actionInit:
|
||||||
|
options.action.projName = ""
|
||||||
|
of actionDump:
|
||||||
|
options.action.projName = ""
|
||||||
|
of actionUpdate:
|
||||||
|
options.action.optionalURL = ""
|
||||||
|
of actionSearch:
|
||||||
|
options.action.search = @[]
|
||||||
|
of actionUninstall:
|
||||||
|
options.action.packages = @[]
|
||||||
|
of actionBuild, actionPublish, actionCustom, actionList, actionNil: discard
|
||||||
|
|
||||||
proc parseCmdLine(): Options =
|
proc parseCmdLine(): Options =
|
||||||
result.action.typ = actionNil
|
result.action.typ = actionNil
|
||||||
result.config = parseConfig()
|
result.config = parseConfig()
|
||||||
|
|
@ -169,45 +224,8 @@ proc parseCmdLine(): Options =
|
||||||
of cmdArgument:
|
of cmdArgument:
|
||||||
if result.action.typ == actionNil:
|
if result.action.typ == actionNil:
|
||||||
compiler_options.command = key
|
compiler_options.command = key
|
||||||
case key.normalize()
|
result.action.typ = parseActionType(key)
|
||||||
of "install", "path":
|
initAction(result, key)
|
||||||
case key.normalize()
|
|
||||||
of "install":
|
|
||||||
result.action.typ = actionInstall
|
|
||||||
of "path":
|
|
||||||
result.action.typ = actionPath
|
|
||||||
else:
|
|
||||||
discard
|
|
||||||
result.action.packages = @[]
|
|
||||||
of "build":
|
|
||||||
result.action.typ = actionBuild
|
|
||||||
of "c", "compile", "js", "cpp", "cc":
|
|
||||||
result.action.typ = actionCompile
|
|
||||||
result.action.compileOptions = @[]
|
|
||||||
result.action.file = ""
|
|
||||||
if key == "c" or key == "compile": result.action.backend = ""
|
|
||||||
else: result.action.backend = key
|
|
||||||
of "init":
|
|
||||||
result.action.typ = actionInit
|
|
||||||
result.action.projName = ""
|
|
||||||
of "dump":
|
|
||||||
result.action.typ = actionDump
|
|
||||||
result.action.projName = ""
|
|
||||||
of "update":
|
|
||||||
result.action.typ = actionUpdate
|
|
||||||
result.action.optionalURL = ""
|
|
||||||
of "search":
|
|
||||||
result.action.typ = actionSearch
|
|
||||||
result.action.search = @[]
|
|
||||||
of "list":
|
|
||||||
result.action.typ = actionList
|
|
||||||
of "uninstall", "remove", "delete", "del", "rm":
|
|
||||||
result.action.typ = actionUninstall
|
|
||||||
result.action.packages = @[]
|
|
||||||
of "publish":
|
|
||||||
result.action.typ = actionPublish
|
|
||||||
else:
|
|
||||||
result.action.typ = actionCustom
|
|
||||||
else:
|
else:
|
||||||
case result.action.typ
|
case result.action.typ
|
||||||
of actionNil:
|
of actionNil:
|
||||||
|
|
@ -993,42 +1011,44 @@ proc uninstall(options: Options) =
|
||||||
removePkgDir(options.getPkgsDir / (pkg.name & '-' & pkg.version), options)
|
removePkgDir(options.getPkgsDir / (pkg.name & '-' & pkg.version), options)
|
||||||
echo("Removed ", pkg.name, " (", $pkg.version, ")")
|
echo("Removed ", pkg.name, " (", $pkg.version, ")")
|
||||||
|
|
||||||
proc getCommand: string = compiler_options.command
|
|
||||||
|
|
||||||
proc doAction(options: Options) =
|
proc doAction(options: Options) =
|
||||||
if not existsDir(options.getNimbleDir()):
|
if not existsDir(options.getNimbleDir()):
|
||||||
createDir(options.getNimbleDir())
|
createDir(options.getNimbleDir())
|
||||||
if not existsDir(options.getPkgsDir):
|
if not existsDir(options.getPkgsDir):
|
||||||
createDir(options.getPkgsDir)
|
createDir(options.getPkgsDir)
|
||||||
|
|
||||||
case getCommand().normalize
|
# The nimscript file may use `setCommand` to set the command so we need to
|
||||||
of "udpate":
|
# re-read it from the compiler.
|
||||||
|
# TODO: It doesn't appear that this actually happens, can we just remove this?
|
||||||
|
var command = compiler_options.command.parseActionType()
|
||||||
|
|
||||||
|
case command
|
||||||
|
of actionUpdate:
|
||||||
update(options)
|
update(options)
|
||||||
of "install":
|
of actionInstall:
|
||||||
discard install(options.action.packages, options)
|
discard install(options.action.packages, options)
|
||||||
of "uninstall", "remove", "delete", "del", "rm":
|
of actionUninstall:
|
||||||
uninstall(options)
|
uninstall(options)
|
||||||
of "search":
|
of actionSearch:
|
||||||
search(options)
|
search(options)
|
||||||
of "list":
|
of actionList:
|
||||||
if options.queryInstalled: listInstalled(options)
|
if options.queryInstalled: listInstalled(options)
|
||||||
else: list(options)
|
else: list(options)
|
||||||
of "path":
|
of actionPath:
|
||||||
listPaths(options)
|
listPaths(options)
|
||||||
of "build":
|
of actionBuild:
|
||||||
build(options)
|
build(options)
|
||||||
of "c", "compile", "js", "cpp", "cc":
|
of actionCompile:
|
||||||
compile(options)
|
compile(options)
|
||||||
of "init":
|
of actionInit:
|
||||||
init(options)
|
init(options)
|
||||||
of "publish":
|
of actionPublish:
|
||||||
var pkgInfo = getPkgInfo(getCurrentDir())
|
var pkgInfo = getPkgInfo(getCurrentDir())
|
||||||
publish(pkgInfo)
|
publish(pkgInfo)
|
||||||
of "dump":
|
of actionDump:
|
||||||
dump(options)
|
dump(options)
|
||||||
of "nop": discard
|
of actionNil, actionCustom:
|
||||||
else:
|
assert false
|
||||||
raise newException(NimbleError, "Unknown command: " & getCommand())
|
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
when defined(release):
|
when defined(release):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue