Implement debug messages and wrap exec output in them.
This commit is contained in:
parent
5fe69b389f
commit
87d6f85aea
3 changed files with 19 additions and 7 deletions
|
|
@ -21,7 +21,7 @@ type
|
||||||
suppressionCount: int ## Amount of messages which were not shown.
|
suppressionCount: int ## Amount of messages which were not shown.
|
||||||
|
|
||||||
Priority* = enum
|
Priority* = enum
|
||||||
LowPriority, MediumPriority, HighPriority
|
DebugPriority, LowPriority, MediumPriority, HighPriority
|
||||||
|
|
||||||
DisplayType* = enum
|
DisplayType* = enum
|
||||||
Error, Warning, Message, Success
|
Error, Warning, Message, Success
|
||||||
|
|
@ -30,8 +30,8 @@ const
|
||||||
longestCategory = len("Downloading")
|
longestCategory = len("Downloading")
|
||||||
foregrounds: array[Error .. Success, ForegroundColor] =
|
foregrounds: array[Error .. Success, ForegroundColor] =
|
||||||
[fgRed, fgYellow, fgCyan, fgGreen]
|
[fgRed, fgYellow, fgCyan, fgGreen]
|
||||||
styles: array[LowPriority .. HighPriority, set[Style]] =
|
styles: array[DebugPriority .. HighPriority, set[Style]] =
|
||||||
[{styleDim}, {}, {styleBright}]
|
[{styleDim}, {styleDim}, {}, {styleBright}]
|
||||||
|
|
||||||
proc newCLI(): CLI =
|
proc newCLI(): CLI =
|
||||||
result = CLI(
|
result = CLI(
|
||||||
|
|
@ -53,7 +53,8 @@ proc displayLine(category, line: string, displayType: DisplayType,
|
||||||
# line.
|
# line.
|
||||||
let offset = calculateCategoryOffset(category)
|
let offset = calculateCategoryOffset(category)
|
||||||
# Display the category.
|
# Display the category.
|
||||||
setForegroundColor(stdout, foregrounds[displayType])
|
if priority != DebugPriority:
|
||||||
|
setForegroundColor(stdout, foregrounds[displayType])
|
||||||
writeStyled("$1$2 " % [repeatChar(offset), category], styles[priority])
|
writeStyled("$1$2 " % [repeatChar(offset), category], styles[priority])
|
||||||
resetAttributes()
|
resetAttributes()
|
||||||
|
|
||||||
|
|
@ -71,8 +72,10 @@ proc display*(category, msg: string, displayType = Message,
|
||||||
globalCLI.warnings.incl(warningPair)
|
globalCLI.warnings.incl(warningPair)
|
||||||
|
|
||||||
# Suppress this message if its priority isn't high enough.
|
# Suppress this message if its priority isn't high enough.
|
||||||
|
# TODO: Per-priority suppression counts?
|
||||||
if priority < globalCLI.level:
|
if priority < globalCLI.level:
|
||||||
globalCLI.suppressionCount.inc
|
if priority != DebugPriority:
|
||||||
|
globalCLI.suppressionCount.inc
|
||||||
return
|
return
|
||||||
|
|
||||||
# Display each line in the message.
|
# Display each line in the message.
|
||||||
|
|
@ -82,6 +85,10 @@ proc display*(category, msg: string, displayType = Message,
|
||||||
displayLine(if i == 0: category else: "...", line, displayType, priority)
|
displayLine(if i == 0: category else: "...", line, displayType, priority)
|
||||||
i.inc
|
i.inc
|
||||||
|
|
||||||
|
proc displayDebug*(category, msg: string) =
|
||||||
|
## Convenience for displaying debug messages.
|
||||||
|
display(category, msg, priority = DebugPriority)
|
||||||
|
|
||||||
proc displayTip*() =
|
proc displayTip*() =
|
||||||
## Called just before Nimble exits. Shows some tips for the user, for example
|
## Called just before Nimble exits. Shows some tips for the user, for example
|
||||||
## the amount of messages that were suppressed and how to show them.
|
## the amount of messages that were suppressed and how to show them.
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,8 @@ Options:
|
||||||
information when searching or listing packages
|
information when searching or listing packages
|
||||||
--nimbleDir dirname Set the Nimble directory.
|
--nimbleDir dirname Set the Nimble directory.
|
||||||
-d --depsOnly Install only dependencies.
|
-d --depsOnly Install only dependencies.
|
||||||
--verbose Show all output.
|
--verbose Show all non-debug output.
|
||||||
|
--debug Show all output including debug messages.
|
||||||
|
|
||||||
For more information read the Github readme:
|
For more information read the Github readme:
|
||||||
https://github.com/nim-lang/nimble#readme
|
https://github.com/nim-lang/nimble#readme
|
||||||
|
|
@ -268,6 +269,7 @@ proc parseFlag*(flag, val: string, result: var Options) =
|
||||||
of "installed", "i": result.queryInstalled = true
|
of "installed", "i": result.queryInstalled = true
|
||||||
of "depsonly", "d": result.depsOnly = true
|
of "depsonly", "d": result.depsOnly = true
|
||||||
of "verbose": result.verbosity = LowPriority
|
of "verbose": result.verbosity = LowPriority
|
||||||
|
of "debug": result.verbosity = DebugPriority
|
||||||
else:
|
else:
|
||||||
raise newException(NimbleError, "Unknown option: --" & flag)
|
raise newException(NimbleError, "Unknown option: --" & flag)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@ proc doCmd*(cmd: string) =
|
||||||
stdout.flushFile()
|
stdout.flushFile()
|
||||||
stderr.flushFile()
|
stderr.flushFile()
|
||||||
|
|
||||||
let exitCode = execCmd(cmd)
|
displayDebug("Executing", cmd)
|
||||||
|
let (output, exitCode) = execCmdEx(cmd)
|
||||||
|
displayDebug("Finished", "with exit code " & $exitCode)
|
||||||
|
displayDebug("Output", output)
|
||||||
|
|
||||||
if exitCode != QuitSuccess:
|
if exitCode != QuitSuccess:
|
||||||
raise newException(NimbleError,
|
raise newException(NimbleError,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue