From bdfb6818244b397eead352dff2b34b02790c407e Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Sat, 19 Aug 2017 21:22:48 +0100 Subject: [PATCH] Fixes #290. --- src/nimble.nim | 2 ++ src/nimblepkg/cli.nim | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/nimble.nim b/src/nimble.nim index 1b2835d..e7058f1 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -650,6 +650,7 @@ proc listPaths(options: Options) = ## but at the end quits with a non zero exit error. ## ## On success the proc returns normally. + cli.setSuppressMessages(true) assert options.action.typ == actionPath assert(not options.action.packages.isNil) @@ -720,6 +721,7 @@ proc getPackageByPattern(pattern: string, options: Options): PackageInfo = result = getPkgInfoFromFile(skeletonInfo.myPath, options) proc dump(options: Options) = + cli.setSuppressMessages(true) let p = getPackageByPattern(options.action.projName, options) echo "name: ", p.name.escape echo "version: ", p.version.escape diff --git a/src/nimblepkg/cli.nim b/src/nimblepkg/cli.nim index 76caaba..0d2a906 100644 --- a/src/nimblepkg/cli.nim +++ b/src/nimblepkg/cli.nim @@ -20,6 +20,10 @@ type warnings: HashSet[(string, string)] suppressionCount: int ## Amount of messages which were not shown. showColor: bool ## Whether messages should be colored. + suppressMessages: bool ## Whether Warning, Message and Success messages + ## should be suppressed, useful for + ## commands like `dump` whose output should be + ## machine readable. Priority* = enum DebugPriority, LowPriority, MediumPriority, HighPriority @@ -42,7 +46,8 @@ proc newCLI(): CLI = level: HighPriority, warnings: initSet[(string, string)](), suppressionCount: 0, - showColor: true + showColor: true, + suppressMessages: false ) var globalCLI = newCLI() @@ -77,6 +82,13 @@ proc displayLine(category, line: string, displayType: DisplayType, proc display*(category, msg: string, displayType = Message, priority = MediumPriority) = + + # Don't print any Warning, Message or Success messages when suppression of + # warnings is enabled. That is, unless the user asked for --verbose output. + if globalCLI.suppressMessages and displayType >= Warning and + globalCLI.level == HighPriority: + return + # Multiple warnings containing the same messages should not be shown. let warningPair = (category, msg) if displayType == Warning: @@ -155,6 +167,9 @@ proc setVerbosity*(level: Priority) = proc setShowColor*(val: bool) = globalCLI.showColor = val +proc setSuppressMessages*(val: bool) = + globalCLI.suppressMessages = val + when isMainModule: display("Reading", "config file at /Users/dom/.config/nimble/nimble.ini", priority = LowPriority)