Skip to content

Commit

Permalink
feat: started work on showing the program's summary
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 256e9e32a2f5f5553fa10d2ce94cadc7c9ef12d39cd464bfad0db75bc1665cce
  • Loading branch information
thindil committed Mar 22, 2024
1 parent 109118a commit 7f6366d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ const
windows): "open" else: "xdg-open" & " {fileName}"
## The command executed when a fix type of rule encounter a problem. By
## default it try to open the selected file in the default editor.
configOptions*: array[16, string] = ["verbosity", "output", "source", "files",
configOptions*: array[17, string] = ["verbosity", "output", "source", "files",
"directory", "check", "search", "count", "fixcommand", "fix", "reset",
"message", "forcefixcommand", "maxreports", "explanation", "ignore"]
"message", "forcefixcommand", "maxreports", "explanation", "ignore",
"showsummary"]
## The list of available the program's configuration's options

proc parseConfig*(configFile: string; sections: var int): tuple[sources: seq[
string]; rules: seq[ConfigData]; fixCommand: string;
maxReports: Natural] {.sideEffect, raises: [], tags: [ReadIOEffect,
maxReports: Natural; showSummary: bool] {.sideEffect, raises: [], tags: [ReadIOEffect,
RootEffect], contractual.} =
## Parse the configuration file and get all the program's settings
##
Expand Down Expand Up @@ -129,6 +130,7 @@ proc parseConfig*(configFile: string; sections: var int): tuple[sources: seq[

result.fixCommand = fixCommand
result.maxReports = Positive.high
result.showSummary = false
try:
# Read the program's configuration
var
Expand Down Expand Up @@ -263,6 +265,20 @@ proc parseConfig*(configFile: string; sections: var int): tuple[sources: seq[
abortProgram(message = "Can't parse the 'explanation' setting in the configuration file, line: " &
$lineNumber & ". No explanation's text set.")
result.rules[result.rules.high].explanation = setting.value
# Set do the progam should show the summary information about the work
# after analyzing the code
of "showsummary":
if setting.value.len == 0:
abortProgram(message = "Can't parse the 'showsummary' setting in the configuration file, line: " &
$lineNumber & ". No value set, should be 0, 1, true or false.")
if setting.value.toLowerAscii in ["0", "false"]:
result.showSummary = false
message(text = "Disabled showing the program's summary information.",
level = lvlDebug)
else:
result.showSummary = true
message(text = "Enabled showing the program's summary information.",
level = lvlDebug)
else:
discard
# Set the program's rule to test the code
Expand Down
14 changes: 11 additions & 3 deletions src/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
## This is the main module of the program.

# Standard library imports
import std/[macros, os, strutils]
import std/[macros, os, strutils, times]
# External modules imports
import compiler/[idents, llstream, options, parser, pathutils]
import colored_logger
Expand All @@ -42,7 +42,8 @@ macro importRules() =
## Returns the list of import statements with the program's rules code as
## modules.
result = newStmtList()
for file in walkDir(dir = getProjectPath().parentDir & DirSep & "src" & DirSep & "rules"):
for file in walkDir(dir = getProjectPath().parentDir & DirSep & "src" &
DirSep & "rules"):
if file.path.endsWith(suffix = ".nim"):
result.add nnkImportStmt.newTree(children =
newIdentNode(i = file.path)
Expand Down Expand Up @@ -72,12 +73,15 @@ proc main() {.raises: [], tags: [ReadIOEffect, WriteIOEffect, RootEffect],
var
resultCode: int = QuitSuccess
configSections: int = 0
globalShowSummary: bool = false
let startTime = cpuTime()
# Check source code files with the selected rules
block checkingCode:
while configSections > -1:
# Read the configuration file and set the program
var (sources, rules, fixCommand, maxResults) = parseConfig(
var (sources, rules, fixCommand, maxResults, showSummary) = parseConfig(
configFile = paramStr(i = 1), sections = configSections)
globalShowSummary = showSummary
# Check if the lists of source code files and rules is set
if sources.len == 0:
abortProgram(message = "No files specified to check. Please enter any files names to the configuration file.")
Expand Down Expand Up @@ -150,6 +154,10 @@ proc main() {.raises: [], tags: [ReadIOEffect, WriteIOEffect, RootEffect],
except OSError:
abortProgram(message = "Can't parse file '" & source &
"'. Reason: ", e = getCurrentException())
if globalShowSummary:
message(text = "SUMMARY:")
message(text = "========")
message(text = "Time taken: " & $(cpuTime() - startTime))
message(text = "Stopping nimalyzer.")
quit resultCode

Expand Down

0 comments on commit 7f6366d

Please sign in to comment.