Skip to content

Commit

Permalink
Merge pull request #11 from daanbreur/vaf-configfile-base
Browse files Browse the repository at this point in the history
WIP: Config parser
  • Loading branch information
d4rckh authored May 15, 2021
2 parents 794eefc + dc991bc commit 28c7504
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/config/importVafConfig.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import json
import os
import strutils

import initVafConfig
import parseVafConfig

import VafConfigStructure

var homeDir: string = os.getHomeDir()

proc importVafConfig*(): VafConfigStructure =
var configExists: bool = fileExists(homedir & "/.vaf.json")
var configContents = readFile(homedir & "/.vaf.json")
var jsonData: JsonNode


if configExists:
jsonData = parseJson(configContents)
# else:
# jsonData = initVafConfig()

return parseVafConfig(jsonData)

36 changes: 36 additions & 0 deletions src/config/parseVafConfig.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import json
import os
import strutils

import VafWordlist
import VafConfigStructure

proc parseWordlist(data: JsonNode): VafWordlist =
var wordlistObject: VafWordlist = VafWordlist()

if data{"Id"} != nil:
wordlistObject.Id = data{"Id"}.getInt()

if data{"Path"} != nil:
wordlistObject.Path = data{"Path"}.getStr()

return wordlistObject

proc parseVafConfig*(data: JsonNode): VafConfigStructure =
var configObject: VafConfigStructure = VafConfigStructure()

echo data

if data{"DefaultWordlist"} == nil:
configObject.DefaultWordlist = -1
else:
configObject.DefaultWordlist = data{"DefaultWordlist"}.getInt()

if data{"Wordlists"} != nil:
for wordlist in data{"Wordlists"}:
configObject.Wordlists.add( parseWordlist( wordlist ))


echo configObject

return configObject

0 comments on commit 28c7504

Please sign in to comment.