From 555ca07e42bf53607453fc9f6c1d23e8e6e9284a Mon Sep 17 00:00:00 2001 From: Matt Haggard Date: Mon, 11 Feb 2019 13:22:27 -0700 Subject: [PATCH 1/3] Add a verbose mode --- README.rst | 2 ++ nake.nim | 2 ++ nakelib.nim | 16 +++++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 8648374..7bc6ed3 100644 --- a/README.rst +++ b/README.rst @@ -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 ============= diff --git a/nake.nim b/nake.nim index a0b8d9e..f9ec096 100644 --- a/nake.nim +++ b/nake.nim @@ -75,6 +75,8 @@ else: validateShellCommands = true of "tasks", "t": printTaskList = true + of "verbose", "v": + verboseMode = true else: discard of cmdArgument: diff --git a/nakelib.nim b/nakelib.nim index eb7005a..c85233b 100644 --- a/nakelib.nim +++ b/nakelib.nim @@ -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. ## @@ -69,7 +73,7 @@ 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'}: @@ -77,6 +81,8 @@ proc askShellCMD (cmd: string): bool {.raises: [ValueError,IOError].} = else: return false else: + if verboseMode: + echo "[nake $1] $#" % [getCurrentDir(), cmd] result = execShellCMD(cmd) == 0 @@ -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, @@ -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>`_, @@ -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() From 5ed4ab15ecaa544e3e7e4b564104369fb2313794 Mon Sep 17 00:00:00 2001 From: Matt Haggard Date: Tue, 12 Feb 2019 13:44:36 -0700 Subject: [PATCH 2/3] Use correct formatting string in verbose mode cmd output --- nakelib.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nakelib.nim b/nakelib.nim index c85233b..7656bdf 100644 --- a/nakelib.nim +++ b/nakelib.nim @@ -82,7 +82,7 @@ proc askShellCMD (cmd: string): bool {.raises: [ValueError,IOError,OSError].} = return false else: if verboseMode: - echo "[nake $1] $#" % [getCurrentDir(), cmd] + echo "[nake $1] $2" % [getCurrentDir(), cmd] result = execShellCMD(cmd) == 0 From 4a7320bfa9a5499c1740c6de23a36c1abb783ae1 Mon Sep 17 00:00:00 2001 From: Matt Haggard Date: Wed, 6 Mar 2019 09:28:43 -0700 Subject: [PATCH 3/3] Keep [nake] formatting --- nakelib.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nakelib.nim b/nakelib.nim index 7656bdf..98fcd2b 100644 --- a/nakelib.nim +++ b/nakelib.nim @@ -82,7 +82,7 @@ proc askShellCMD (cmd: string): bool {.raises: [ValueError,IOError,OSError].} = return false else: if verboseMode: - echo "[nake $1] $2" % [getCurrentDir(), cmd] + echo "[nake] $1 $2" % [getCurrentDir(), cmd] result = execShellCMD(cmd) == 0