Compare commits
2 Commits
9219d3e86e
...
1.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d49243a88 | |||
| b0095153fc |
+10
-3
@@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "1.0.0"
|
version = "1.0.2"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Small utility to pretty-print strucutured logs."
|
description = "Small utility to pretty-print strucutured logs."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@@ -10,5 +10,12 @@ bin = @["slfmt"]
|
|||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
requires @["nim >= 2.2.0", "docopt >= 0.7.1"]
|
requires "nim >= 2.2.0"
|
||||||
requires @["cliutils >= 0.11.0", "timeutils", "zero_functional"]
|
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"
|
||||||
|
|||||||
+27
-10
@@ -5,7 +5,7 @@ import cliutils, docopt, timeutils, zero_functional
|
|||||||
from std/logging import Level
|
from std/logging import Level
|
||||||
import std/nre except toSeq
|
import std/nre except toSeq
|
||||||
|
|
||||||
const VERSION = "1.0.0"
|
const VERSION = "1.0.2"
|
||||||
|
|
||||||
const USAGE = """Usage:
|
const USAGE = """Usage:
|
||||||
slfmt [options]
|
slfmt [options]
|
||||||
@@ -47,7 +47,12 @@ Options:
|
|||||||
|
|
||||||
--config <cfgFile>
|
--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,
|
expected: isExpected,
|
||||||
count: 0))
|
count: 0))
|
||||||
|
|
||||||
if args["--config"]:
|
# TODO: Consider refactoring and moving this outside of this function. Right
|
||||||
let filename = $args["--config"]
|
# now the config file is only used to store expectation configuration, but if
|
||||||
if not fileExists(filename):
|
# that ever changes and we have additional config data then this confuses the
|
||||||
stderr.writeLine("slfmt - WARN: " &
|
# purpose of this function. We should parse the config separately and pass
|
||||||
filename & " does not exist, ignoring")
|
# 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:
|
try:
|
||||||
let cfg: JsonNode = parseFile(filename)
|
let cfg: JsonNode = parseFile(configFilename)
|
||||||
for expJson in cfg.getElems:
|
for expJson in cfg.getElems:
|
||||||
var exp = Expectation(
|
var exp = Expectation(
|
||||||
fieldName: expJson.getOrFail("fieldName").getStr,
|
fieldName: expJson.getOrFail("fieldName").getStr,
|
||||||
@@ -389,8 +404,10 @@ proc parseExpectations(args: Table[string, docopt.Value]): seq[Expectation] =
|
|||||||
result.add(exp)
|
result.add(exp)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
stderr.writeLine("slfmt - WARN: unable to parse config file, ignoring.")
|
if not configRequired:
|
||||||
stderr.writeLine("slfmt - DEBUG: " & getCurrentExceptionMsg())
|
stderr.writeLine("slfmt - WARN: unable to parse config file, ignoring.")
|
||||||
|
stderr.writeLine("slfmt - DEBUG: " & getCurrentExceptionMsg())
|
||||||
|
else: raise getCurrentException()
|
||||||
|
|
||||||
|
|
||||||
proc eraseAndWriteLine(f: File, s: string) =
|
proc eraseAndWriteLine(f: File, s: string) =
|
||||||
|
|||||||
Reference in New Issue
Block a user