Skip to content

Commit

Permalink
feat: fix .git dir erro issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 16, 2020
1 parent 3450099 commit 562fcd8
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion cmd/cloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"fmt"
"github.com/boyter/scc/processor"
"github.com/phodal/coca/cmd/config"
"github.com/phodal/coca/pkg/domain/cloc"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
)

type CocaClocConfig struct {
Expand Down Expand Up @@ -42,15 +45,35 @@ var clocCmd = &cobra.Command{

processor.Format = "cloc-yaml"

var outputFiles []string
for _, dir := range dirs {
baseName := filepath.Base(dir)
if baseName == ".git" || baseName == ".svn" || baseName == ".hg" {
continue
}
processor.DirFilePaths = []string{dir}
processor.FileOutput = filepath.FromSlash(config.CocaConfig.ReporterPath + "/cloc/" + baseName + ".yaml")
outputFile := filepath.FromSlash(config.CocaConfig.ReporterPath + "/cloc/" + baseName + ".yaml")
outputFiles = append(outputFiles, outputFile)
processor.FileOutput = outputFile
processor.ConfigureGc()
processor.ConfigureLazy(true)
processor.Process()
}

var summaryMap = make(map[string]cloc.ClocSummary)
for _, file := range outputFiles {
var summary = cloc.ClocSummary{}
contents, _ := ioutil.ReadFile(file)
baseName := strings.TrimSuffix(filepath.Base(file), filepath.Ext(file))
err := yaml.Unmarshal(contents, &summary)
if err != nil {
panic(err);
}
summaryMap[baseName] = summary
}

fmt.Println(summaryMap)

return
} else {
processor.DirFilePaths = args
Expand Down

0 comments on commit 562fcd8

Please sign in to comment.