Skip to content

Commit

Permalink
feat: init by files
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 17, 2020
1 parent 7a3eecb commit decb12a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/cloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"log"
"os"
"path/filepath"
"strings"
)

type CocaClocConfig struct {
Expand All @@ -31,8 +32,13 @@ var clocCmd = &cobra.Command{
Version: processor.Version,
Run: func(cmd *cobra.Command, args []string) {
if clocConfig.ByDirectory {
_ = createClocDir()
processByDirectory(args[0])
return
} else if clocConfig.TopFile {
_ = createClocDir()
processTopFile(args[0])
return
} else {
processor.DirFilePaths = args
}
Expand All @@ -50,6 +56,17 @@ func runProcessor() {
processor.Process()
}

func processTopFile(dir string) {
processor.DirFilePaths = []string{dir}
processor.Format = "json"
processor.Files = true
processor.FileOutput = filepath.FromSlash(config.CocaConfig.ReporterPath + "/top_cloc.json")

runProcessor()

//content := cmd_util.ReadCocaFile("top_cloc.json")
}

func processByDirectory(firstDir string) {
var dirs []string
firstFile, err := ioutil.ReadDir(firstDir)
Expand All @@ -65,7 +82,6 @@ func processByDirectory(firstDir string) {

processor.Format = "json"

_ = createClocDir()
baseCloc := config.CocaConfig.ReporterPath + "/base_cloc.json"
processBaseCloc(filepath.FromSlash(firstDir), baseCloc)
keys := buildBaseKey(baseCloc)
Expand Down Expand Up @@ -146,6 +162,7 @@ func writeToCsv(data [][]string) {
defer writer.Flush()

for _, value := range data {
fmt.Fprintln(output, strings.Join(value, ","))
err := writer.Write(value)
checkError("Cannot write to file", err)
}
Expand Down

0 comments on commit decb12a

Please sign in to comment.