diff --git a/src/takajo.nim b/src/takajo.nim index e3002001..df5695e6 100644 --- a/src/takajo.nim +++ b/src/takajo.nim @@ -1,4 +1,5 @@ import takajopkg/submodule +import std/sequtils import docopt @@ -6,14 +7,14 @@ let doc = """ takajo Usage: - takajo + takajo -c -t takajo (-h | --help) takajo --version Options: -h --help Show this screen. --version Show version. - -c --check-undetected= Check no detected rule file in hayabusa-rules directory. + -c --check-undetected= Check no detected rule file in hayabusa-rules directory. -t --target-column= Specified target column header name when check detected rule file """ @@ -22,10 +23,26 @@ when isMainModule: let args = docopt(doc) if args[""]: let csvData = getHayabusaCsvData($args[""]) - if args[""]: - let rulePath: string = args[""] - 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[""]: - let targetColumn = args[""] - csvData[targetColumn] diff --git a/src/takajopkg/submodule.nim b/src/takajopkg/submodule.nim index b9b9e33b..b23613ea 100644 --- a/src/takajopkg/submodule.nim +++ b/src/takajopkg/submodule.nim @@ -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. diff --git a/tests/testsubmodule.nim b/tests/testsubmodule.nim index 9d55b062..7f66e960 100644 --- a/tests/testsubmodule.nim +++ b/tests/testsubmodule.nim @@ -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