Implemented `tasks` command.

This commit is contained in:
Dominik Picheta 2015-12-23 13:33:14 +00:00
commit 0fcf0b2de9
2 changed files with 29 additions and 6 deletions

View file

@ -43,11 +43,11 @@ type
actionNil, actionUpdate, actionInit, actionDump, actionPublish, actionNil, actionUpdate, actionInit, actionDump, actionPublish,
actionInstall, actionSearch, actionInstall, actionSearch,
actionList, actionBuild, actionPath, actionUninstall, actionCompile, actionList, actionBuild, actionPath, actionUninstall, actionCompile,
actionCustom actionCustom, actionTasks
Action = object Action = object
case typ: ActionType case typ: ActionType
of actionNil, actionList, actionBuild, actionPublish: nil of actionNil, actionList, actionBuild, actionPublish, actionTasks: nil
of actionUpdate: of actionUpdate:
optionalURL: string # Overrides default package list. optionalURL: string # Overrides default package list.
of actionInstall, actionPath, actionUninstall: of actionInstall, actionPath, actionUninstall:
@ -87,6 +87,8 @@ Commands:
performed by tag and by name. performed by tag and by name.
list [--ver] Lists all packages. list [--ver] Lists all packages.
[-i, --installed] Lists all installed packages. [-i, --installed] Lists all installed packages.
tasks Lists the tasks specified in the Nimble
package's Nimble file.
path pkgname ... Shows absolute path to the installed packages path pkgname ... Shows absolute path to the installed packages
specified. specified.
dump [pkgname] Outputs Nimble package information for dump [pkgname] Outputs Nimble package information for
@ -189,6 +191,8 @@ proc parseActionType(action: string): ActionType =
result = actionUninstall result = actionUninstall
of "publish": of "publish":
result = actionPublish result = actionPublish
of "tasks":
result = actionTasks
else: else:
result = actionCustom result = actionCustom
@ -214,7 +218,8 @@ proc initAction(options: var Options, key: string) =
options.action.search = @[] options.action.search = @[]
of actionUninstall: of actionUninstall:
options.action.packages = @[] options.action.packages = @[]
of actionBuild, actionPublish, actionCustom, actionList, actionNil: discard of actionBuild, actionPublish, actionCustom, actionList, actionTasks,
actionNil: discard
proc parseCmdLine(): Options = proc parseCmdLine(): Options =
result.action.typ = actionNil result.action.typ = actionNil
@ -1011,6 +1016,12 @@ 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 listTasks(options: Options) =
let (isNimScript, nimbleFile) = findNimbleFile(getCurrentDir(), true)
if not isNimScript:
echo("No tasks defined (Found Nimble file, but no NimScript file)")
nimscriptsupport.listTasks(nimbleFile)
proc doAction(options: Options) = proc doAction(options: Options) =
if not existsDir(options.getNimbleDir()): if not existsDir(options.getNimbleDir()):
createDir(options.getNimbleDir()) createDir(options.getNimbleDir())
@ -1019,7 +1030,9 @@ proc doAction(options: Options) =
var command = getNimScriptCommand().parseActionType() var command = getNimScriptCommand().parseActionType()
# The loop is necessary to support tasks using `setCommand`. # The loop is necessary to support tasks using `setCommand`.
while true: var moreCommands = true
while moreCommands:
moreCommands = false
case command case command
of actionUpdate: of actionUpdate:
update(options) update(options)
@ -1045,6 +1058,8 @@ proc doAction(options: Options) =
publish(pkgInfo) publish(pkgInfo)
of actionDump: of actionDump:
dump(options) dump(options)
of actionTasks:
listTasks(options)
of actionNil: of actionNil:
assert false assert false
of actionCustom: of actionCustom:
@ -1060,7 +1075,7 @@ proc doAction(options: Options) =
echo("WARNING: Using `setCommand 'nop'` is not necessary.") echo("WARNING: Using `setCommand 'nop'` is not necessary.")
break break
command = getNimScriptCommand().parseActionType() command = getNimScriptCommand().parseActionType()
if not hasTaskRequestedCommand(): break moreCommands = hasTaskRequestedCommand()
when isMainModule: when isMainModule:
when defined(release): when defined(release):

View file

@ -162,4 +162,12 @@ proc setNimScriptCommand*(command: string) =
proc hasTaskRequestedCommand*(): bool = proc hasTaskRequestedCommand*(): bool =
## Determines whether the last executed task used ``setCommand`` ## Determines whether the last executed task used ``setCommand``
return getNimScriptCommand() != internalCmd return getNimScriptCommand() != internalCmd
proc listTasks*(scriptName: string) =
setNimScriptCommand("help")
execScript(scriptName)
# TODO: Make the 'task' template generate explicit data structure containing
# all the task names + descriptions.
cleanup()