Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verbose mode #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ specifying a task. Example:
echo "Binary is fresh, anything else?"
listTasks()

If you would like verbose output, including printing out the task names and
shell commands being run, run with ``-v`` or ``--verbose``.

Documentation
=============
Expand Down
2 changes: 2 additions & 0 deletions nake.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ else:
validateShellCommands = true
of "tasks", "t":
printTaskList = true
of "verbose", "v":
verboseMode = true
else:
discard
of cmdArgument:
Expand Down
16 changes: 13 additions & 3 deletions nakelib.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ var
## `direShell() <#direShell>`_ procs to ask the user for confirmation before
## executing a command.

verboseMode* = false ## \
## Set this global to ``true`` if you want to display all tasks and commands
## that are run.

nimExe*: string ## \
## Full path to the Nim compiler binary.
##
Expand All @@ -69,14 +73,16 @@ if nimExe.len < 1:
nimExe = nimExe.quoteShell()


proc askShellCMD (cmd: string): bool {.raises: [ValueError,IOError].} =
proc askShellCMD (cmd: string): bool {.raises: [ValueError,IOError,OSError].} =
if validateShellCommands:
let ans = readLineFromSTDIN("Run? `$#` [N/y]\L" % cmd)
if ans[0] in {'y','Y'}:
result = execShellCMD(cmd) == 0
else:
return false
else:
if verboseMode:
echo "[nake] $1 $2" % [getCurrentDir(), cmd]
result = execShellCMD(cmd) == 0


Expand All @@ -97,11 +103,13 @@ proc askSilentShellCMD(cmd: string):
result.output = ""
result.exitCode = -1
else:
if verboseMode:
echo "[nake] $#" % cmd
result = execCmdEx(cmd)


proc shell*(cmd: varargs[string, `$`]): bool {.discardable,
raises:[ValueError,IOError] .} =
raises:[ValueError,IOError,OSError] .} =
## Invokes an external command.
##
## The proc will return ``false`` if the command exits with a non zero code,
Expand All @@ -113,7 +121,7 @@ proc shell*(cmd: varargs[string, `$`]): bool {.discardable,


proc direShell*(cmd: varargs[string, `$`]): bool {.discardable,
raises:[ValueError,IOError].} =
raises:[ValueError,IOError,OSError].} =
## Wrapper around the `shell() <#shell>`_ proc.
##
## Instead of returning on a non zero value like `shell() <#shell>`_,
Expand Down Expand Up @@ -249,6 +257,8 @@ proc runTask*(name: string) {.inline.} = ## \
## runTask("docs")
## echo "Copying documentation to " & docInstallDir
## copyFile(moduleHtml, docInstallDir / moduleHtml)
if verboseMode:
echo "[nake] " & name
tasks[name].action()


Expand Down