Compare commits

...

3 Commits
1.0.12 ... main

Author SHA1 Message Date
c00be8c1fc Add asdf tool-versions definitions pinning this to Nim 1.6 2024-05-10 11:59:58 -05:00
96ee649bf6 Change the logic around how we load our config.
The previous logic that was intended to find the first non-empty
filename that represented a valid file location was wrong. Replaced with
a simpler filter-based version.

Additionally, if the user provides a specific configuration filename, we
no longer fall back to the defaults if it is not found. Instead we just
err out and inform them that the file the specified was not found.
2022-04-02 08:45:30 -05:00
69177ffa17 Log locations when unable to load config.
When we can't find a config file, log all the locations we looked and
don't create a new file in $HOME/.ptkrc.

There is currently an intermittent bug in the config loading logic that
is leading to the default config file in $HOME/.ptkrc not being found
and then being overwritten with the default config. This is step one in
fixing it.
2022-03-19 08:49:26 -05:00
4 changed files with 12 additions and 17 deletions

1
.tool-versions Normal file
View File

@ -0,0 +1 @@
nim 1.6.20

View File

@ -1 +1 @@
const PTK_VERSION* = "1.0.12"
const PTK_VERSION* = "1.0.14"

24
ptk.nim
View File

@ -307,27 +307,21 @@ Options:
quit()
# Find and parse the .ptkrc file
let ptkrcLocations = @[
if args["--config"]: $args["--config"] else:"",
".ptkrc", $getEnv("PTKRC"), $getEnv("HOME") & "/.ptkrc"]
let ptkrcLocations =
if args["--config"]: @[$args["--config"]]
else: @[".ptkrc", $getEnv("PTKRC"), $getEnv("HOME") & "/.ptkrc"]
var ptkrcFilename: string =
foldl(ptkrcLocations, if len(a) > 0: a elif fileExists(b): b else: "")
let foundPtkrcLocations =
ptkrcLocations.filterIt(it.len > 0 and fileExists(it))
var cfg: JsonNode
var cfgFile: File
if not fileExists(ptkrcFilename):
if foundPtkrcLocations.len < 1:
warn "ptk: could not find .ptkrc file."
ptkrcFilename = $getEnv("HOME") & "/.ptkrc"
try:
cfgFile = open(ptkrcFilename, fmWrite)
cfgFile.write("{\"timelineLogFile\": \"timeline.log.json\"}")
except: warn "ptk: could not write default .ptkrc to " & ptkrcFilename
finally: close(cfgFile)
debug "ptk: considered the following locations:\n\t" & ptkrcLocations.join("\n\t")
try: cfg = parseFile(ptkrcFilename)
try: cfg = parseFile(foundPtkrcLocations[0])
except: raise newException(IOError,
"unable to read config file: " & ptkrcFilename &
"unable to read config file: " & foundPtkrcLocations[0] &
"\x0D\x0A" & getCurrentExceptionMsg())
# Find the time log file

View File

@ -1,6 +1,6 @@
# Package
version = "1.0.12"
version = "1.0.14"
author = "Jonathan Bernard"
description = "Personal Time Keeper"
license = "MIT"