Implement message suppression.
This commit is contained in:
parent
dcbbb8b62e
commit
8ebc4bb7c1
2 changed files with 29 additions and 5 deletions
|
|
@ -996,12 +996,18 @@ proc doAction(options: Options) =
|
||||||
discard execHook(options, false)
|
discard execHook(options, false)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
let error = ""
|
||||||
when defined(release):
|
when defined(release):
|
||||||
try:
|
try:
|
||||||
parseCmdLine().doAction()
|
parseCmdLine().doAction()
|
||||||
except NimbleError:
|
except NimbleError:
|
||||||
quit("FAILURE: " & getCurrentExceptionMsg())
|
error = getCurrentExceptionMsg()
|
||||||
finally:
|
finally:
|
||||||
removeDir(getNimbleTempDir())
|
removeDir(getNimbleTempDir())
|
||||||
else:
|
else:
|
||||||
parseCmdLine().doAction()
|
parseCmdLine().doAction()
|
||||||
|
|
||||||
|
displayTip()
|
||||||
|
if error.len > 0:
|
||||||
|
display("Error", error, Error, HighPriority)
|
||||||
|
quit(1)
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,12 @@ import logging, terminal, sets, strutils
|
||||||
|
|
||||||
type
|
type
|
||||||
CLI* = ref object
|
CLI* = ref object
|
||||||
|
level: Priority
|
||||||
warnings: HashSet[(string, string)]
|
warnings: HashSet[(string, string)]
|
||||||
|
suppressionCount: int ## Amount of messages which were not shown.
|
||||||
|
|
||||||
Priority* = enum
|
Priority* = enum
|
||||||
HighPriority, MediumPriority, LowPriority
|
LowPriority, MediumPriority, HighPriority
|
||||||
|
|
||||||
DisplayType* = enum
|
DisplayType* = enum
|
||||||
Error, Warning, Message, Success
|
Error, Warning, Message, Success
|
||||||
|
|
@ -28,12 +30,14 @@ 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[HighPriority .. LowPriority, set[Style]] =
|
styles: array[LowPriority .. HighPriority, set[Style]] =
|
||||||
[{styleBright}, {}, {styleDim}]
|
[{styleDim}, {}, {styleBright}]
|
||||||
|
|
||||||
proc newCLI(): CLI =
|
proc newCLI(): CLI =
|
||||||
result = CLI(
|
result = CLI(
|
||||||
warnings: initSet[(string, string)]()
|
level: HighPriority,
|
||||||
|
warnings: initSet[(string, string)](),
|
||||||
|
suppressionCount: 0
|
||||||
)
|
)
|
||||||
|
|
||||||
var globalCLI = newCLI()
|
var globalCLI = newCLI()
|
||||||
|
|
@ -66,6 +70,11 @@ proc display*(category, msg: string, displayType = Message,
|
||||||
else:
|
else:
|
||||||
globalCLI.warnings.incl(warningPair)
|
globalCLI.warnings.incl(warningPair)
|
||||||
|
|
||||||
|
# Suppress this message if its priority isn't high enough.
|
||||||
|
if priority < globalCLI.level:
|
||||||
|
globalCLI.suppressionCount.inc
|
||||||
|
return
|
||||||
|
|
||||||
# Display each line in the message.
|
# Display each line in the message.
|
||||||
var i = 0
|
var i = 0
|
||||||
for line in msg.splitLines():
|
for line in msg.splitLines():
|
||||||
|
|
@ -73,6 +82,15 @@ 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 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.
|
||||||
|
if globalCLI.suppressionCount > 0:
|
||||||
|
let msg = "$1 messages have been suppressed, use --verbose to show them." %
|
||||||
|
$globalCLI.suppressionCount
|
||||||
|
display("Tip", msg, Warning, HighPriority)
|
||||||
|
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
display("Reading", "config file at /Users/dom/.config/nimble/nimble.ini",
|
display("Reading", "config file at /Users/dom/.config/nimble/nimble.ini",
|
||||||
priority = LowPriority)
|
priority = LowPriority)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue