Compare commits
2 Commits
9219d3e86e
..
1.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d49243a88 | |||
| b0095153fc |
+10
-3
@@ -1,6 +1,6 @@
|
||||
# Package
|
||||
|
||||
version = "1.0.0"
|
||||
version = "1.0.2"
|
||||
author = "Jonathan Bernard"
|
||||
description = "Small utility to pretty-print strucutured logs."
|
||||
license = "MIT"
|
||||
@@ -10,5 +10,12 @@ bin = @["slfmt"]
|
||||
|
||||
# Dependencies
|
||||
|
||||
requires @["nim >= 2.2.0", "docopt >= 0.7.1"]
|
||||
requires @["cliutils >= 0.11.0", "timeutils", "zero_functional"]
|
||||
requires "nim >= 2.2.0"
|
||||
requires "docopt >= 0.7.1"
|
||||
requires "cliutils >= 0.11.0"
|
||||
requires "timeutils"
|
||||
requires "zero_functional"
|
||||
requires "update_version"
|
||||
|
||||
task updateVersion, "Update the version of this package.":
|
||||
exec "update_version interactive src/slfmt.nim"
|
||||
|
||||
+25
-8
@@ -5,7 +5,7 @@ import cliutils, docopt, timeutils, zero_functional
|
||||
from std/logging import Level
|
||||
import std/nre except toSeq
|
||||
|
||||
const VERSION = "1.0.0"
|
||||
const VERSION = "1.0.2"
|
||||
|
||||
const USAGE = """Usage:
|
||||
slfmt [options]
|
||||
@@ -47,7 +47,12 @@ Options:
|
||||
|
||||
--config <cfgFile>
|
||||
|
||||
Read expectation data from a json config file formatted as follows:
|
||||
Read expectation data from a json config file. slfmt will, by default,
|
||||
try to read from a file named `slfmt.config.json`, but will silently
|
||||
ignore its absence. When --config is passed, slfmt will fail if the
|
||||
named file is not found.
|
||||
|
||||
The config file is expected to be formatted as follows:
|
||||
|
||||
[
|
||||
{
|
||||
@@ -315,14 +320,24 @@ proc parseExpectations(args: Table[string, docopt.Value]): seq[Expectation] =
|
||||
expected: isExpected,
|
||||
count: 0))
|
||||
|
||||
if args["--config"]:
|
||||
let filename = $args["--config"]
|
||||
if not fileExists(filename):
|
||||
stderr.writeLine("slfmt - WARN: " &
|
||||
filename & " does not exist, ignoring")
|
||||
# TODO: Consider refactoring and moving this outside of this function. Right
|
||||
# now the config file is only used to store expectation configuration, but if
|
||||
# that ever changes and we have additional config data then this confuses the
|
||||
# purpose of this function. We should parse the config separately and pass
|
||||
# that into this function to extract expectations.
|
||||
var configFilename = "slfmt.config.json"
|
||||
var configRequired = false
|
||||
|
||||
if args["--config"]:
|
||||
configFilename = $args["--config"]
|
||||
configRequired = true
|
||||
|
||||
if not fileExists(configFilename):
|
||||
if configRequired:
|
||||
raise newException(IOError, configFilename & " does not exist")
|
||||
else: # file exists
|
||||
try:
|
||||
let cfg: JsonNode = parseFile(filename)
|
||||
let cfg: JsonNode = parseFile(configFilename)
|
||||
for expJson in cfg.getElems:
|
||||
var exp = Expectation(
|
||||
fieldName: expJson.getOrFail("fieldName").getStr,
|
||||
@@ -389,8 +404,10 @@ proc parseExpectations(args: Table[string, docopt.Value]): seq[Expectation] =
|
||||
result.add(exp)
|
||||
|
||||
except:
|
||||
if not configRequired:
|
||||
stderr.writeLine("slfmt - WARN: unable to parse config file, ignoring.")
|
||||
stderr.writeLine("slfmt - DEBUG: " & getCurrentExceptionMsg())
|
||||
else: raise getCurrentException()
|
||||
|
||||
|
||||
proc eraseAndWriteLine(f: File, s: string) =
|
||||
|
||||
Reference in New Issue
Block a user