diff --git a/go.mod b/go.mod index 7c7f51c6..7ff565a4 100644 --- a/go.mod +++ b/go.mod @@ -25,4 +25,5 @@ require ( github.com/yudai/pp v2.0.1+incompatible // indirect golang.org/x/exp v0.0.0-20191224044220-1fea468a75e9 // indirect gonum.org/v1/gonum v0.6.2 + gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 0fd6b1e3..3a32175b 100644 --- a/go.sum +++ b/go.sum @@ -161,4 +161,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/pkg/domain/cloc/cloc_summary.go b/pkg/domain/cloc/cloc_summary.go new file mode 100644 index 00000000..14aed57d --- /dev/null +++ b/pkg/domain/cloc/cloc_summary.go @@ -0,0 +1,39 @@ +package cloc + +// LanguageSummary to generate output like cloc +type LanguageSummaryCloc struct { + Name string `yaml:"name"` + Code int64 `yaml:"code"` + Comment int64 `yaml:"comment"` + Blank int64 `yaml:"blank"` + Count int64 `yaml:"nFiles"` +} + +type SummaryStruct struct { + Code int64 `yaml:"code"` + Comment int64 `yaml:"comment"` + Blank int64 `yaml:"blank"` + Count int64 `yaml:"nFiles"` +} + +type HeaderStruct struct { + Url string `yaml:"url"` + Version string `yaml:"version"` + ElapsedSeconds float64 `yaml:"elapsed_seconds"` + NFiles int64 `yaml:"n_files"` + NLines int64 `yaml:"n_lines"` + FilesPerSecond float64 `yaml:"files_per_second"` + LinesPerSecond float64 `yaml:"lines_per_second"` +} + +type LanguageReportStart struct { + Header HeaderStruct +} + +type LanguageReportEnd struct { + Sum SummaryStruct `yaml:"SUM"` +} + +type ClocSummary struct { + Header HeaderStruct +} diff --git a/pkg/domain/cloc/cloc_summary_test.go b/pkg/domain/cloc/cloc_summary_test.go new file mode 100644 index 00000000..ca0db669 --- /dev/null +++ b/pkg/domain/cloc/cloc_summary_test.go @@ -0,0 +1,36 @@ +package cloc + + +import ( + "fmt" + . "github.com/onsi/gomega" + "gopkg.in/yaml.v2" + "log" + "testing" +) + +func Test_Yaml_Parse_Model(t *testing.T) { + t.Parallel() + g := NewGomegaWithT(t) + + + var data = ` +header: + url: https://github.com/boyter/scc/ + version: 2.13.0 + elapsed_seconds: 0.006 + n_files: 25 + n_lines: 4045 + files_per_second: 4166.666666666667 + lines_per_second: 674166.6666666666 + +` + + var header = LanguageReportStart{} + err := yaml.Unmarshal([]byte(data), &header) + if err != nil { + log.Fatalf("error: %v", header) + } + + g.Expect(header.Header.Version).To(Equal("2.13.0")) +} \ No newline at end of file