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.
|
||||
|
||||
Priority* = enum
|
||||
LowPriority, MediumPriority, HighPriority
|
||||
DebugPriority, LowPriority, MediumPriority, HighPriority
|
||||
|
||||
DisplayType* = enum
|
||||
Error, Warning, Message, Success
|
||||
|
|
@ -30,8 +30,8 @@ const
|
|||
longestCategory = len("Downloading")
|
||||
foregrounds: array[Error .. Success, ForegroundColor] =
|
||||
[fgRed, fgYellow, fgCyan, fgGreen]
|
||||
styles: array[LowPriority .. HighPriority, set[Style]] =
|
||||
[{styleDim}, {}, {styleBright}]
|
||||
styles: array[DebugPriority .. HighPriority, set[Style]] =
|
||||
[{styleDim}, {styleDim}, {}, {styleBright}]
|
||||
|
||||
proc newCLI(): CLI =
|
||||
result = CLI(
|
||||
|
|
@ -53,7 +53,8 @@ proc displayLine(category, line: string, displayType: DisplayType,
|
|||
# line.
|
||||
let offset = calculateCategoryOffset(category)
|
||||
# Display the category.
|
||||
setForegroundColor(stdout, foregrounds[displayType])
|
||||
if priority != DebugPriority:
|
||||
setForegroundColor(stdout, foregrounds[displayType])
|
||||
writeStyled("$1$2 " % [repeatChar(offset), category], styles[priority])
|
||||
resetAttributes()
|
||||
|
||||
|
|
@ -71,8 +72,10 @@ proc display*(category, msg: string, displayType = Message,
|
|||
globalCLI.warnings.incl(warningPair)
|
||||
|
||||
# Suppress this message if its priority isn't high enough.
|
||||
# TODO: Per-priority suppression counts?
|
||||
if priority < globalCLI.level:
|
||||
globalCLI.suppressionCount.inc
|
||||
if priority != DebugPriority:
|
||||
globalCLI.suppressionCount.inc
|
||||
return
|
||||
|
||||
# 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)
|
||||
i.inc
|
||||
|
||||
proc displayDebug*(category, msg: string) =
|
||||
## Convenience for displaying debug messages.
|
||||
display(category, msg, priority = DebugPriority)
|
||||
|
||||
proc displayTip*() =
|
||||
## 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.
|
||||
|
|
|
|||
|
|
@ -85,7 +85,8 @@ Options:
|
|||
information when searching or listing packages
|
||||
--nimbleDir dirname Set the Nimble directory.
|
||||
-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:
|
||||
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 "depsonly", "d": result.depsOnly = true
|
||||
of "verbose": result.verbosity = LowPriority
|
||||
of "debug": result.verbosity = DebugPriority
|
||||
else:
|
||||
raise newException(NimbleError, "Unknown option: --" & flag)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,10 @@ proc doCmd*(cmd: string) =
|
|||
stdout.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:
|
||||
raise newException(NimbleError,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue