Skip to content

Commit

Permalink
added feature of list up rule files can not be detected #4
Browse files Browse the repository at this point in the history
  • Loading branch information
hitenkoku committed Sep 30, 2022
1 parent 30e7d0e commit f8e14bf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
33 changes: 25 additions & 8 deletions src/takajo.nim
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import takajopkg/submodule
import std/sequtils

import docopt

let doc = """
takajo
Usage:
takajo <CSV-FILE>
takajo <CSV-FILE> -c <hayabusa-rulespath> -t <column>
takajo (-h | --help)
takajo --version
Options:
-h --help Show this screen.
--version Show version.
-c --check-undetected=<hayabusa-rulespath> Check no detected rule file in hayabusa-rules directory.
-c --check-undetected=<hayabusa-rulespath> Check no detected rule file in hayabusa-rules directory.
-t --target-column=<column> Specified target column header name when check detected rule file
"""

Expand All @@ -22,10 +23,26 @@ when isMainModule:
let args = docopt(doc)
if args["<CSV-FILE>"]:
let csvData = getHayabusaCsvData($args["<CSV-FILE>"])
if args["<hayabusa-rulespath>"]:
let rulePath: string = args["<hayabusa-rulespath>"]
for f in walkDirRec(rulePath, "*.yml"):
var ymlLists: seq[string]
if args["--check-undetected"]:
let rulePath: string = $args["--check-undetected"]
ymlLists = getYMLLists(rulePath)
if args["--target-column"]:
let targetColumn = $args["--target-column"]
var detectedRulePath: seq[string] = csvData[targetColumn]
detectedRulePath = deduplicate(detectedRulePath)
if ymlLists.len() == 0:
quit("yml file does not exist in specified directory. Please check -c option.")
else:
var output: seq[string] = @[]
var cnt = 0
for ymlFile in ymlLists:
if ymlFile in detectedRulePath:
output.add(ymlFile)
cnt += 1
echo "Finished check. "
echo "---------------"
echo "Undetected rules:"
for undetectedYmlFile in output:
echo " - ", undetectedYmlFile

if args["c"] == true and args["<column>"]:
let targetColumn = args["<column>"]
csvData[targetColumn]
9 changes: 7 additions & 2 deletions src/takajopkg/submodule.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import std/tables
import std/parsecsv
import std/os
import std/strutils
import std/sequtils
from std/streams import newFileStream

proc getYMLLists*(targetDirPath: string): seq[string] =
## extract yml file name seq to specified directory path
var r: seq[string] = @[]
for f in walkDirRec(targetDirPath):
if f.endsWith(".yml"):
r.insert(f)
return r
var (_, file, ext) = splitFile(f)
file &= ext
r.insert(file)
# removed duplicated file name from seq
return deduplicate(r)

proc getHayabusaCsvData*(csvPath: string): Tableref[string, seq[string]] =
## procedure for Hayabusa output csv read data.
Expand Down
2 changes: 1 addition & 1 deletion tests/testsubmodule.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ test "csv file path import":
check getHayabusaCsvData("./tests/data/1.csv") == expect_table

test "check getYMLLists":
let expect = @["tests\\data\\1.yml"]
let expect = @["1.yml"]
check getYMLLists("./tests") == expect

0 comments on commit f8e14bf

Please sign in to comment.