Skip to content

Commit

Permalink
support cloc-xml output in language total
Browse files Browse the repository at this point in the history
  • Loading branch information
Hideo Hattori committed Jan 12, 2018
1 parent eb5ea00 commit caee9f2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
9 changes: 9 additions & 0 deletions language.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ import (
enry "gopkg.in/src-d/enry.v1"
)

// ClocLanguage is provide for xml-cloc format
type ClocLanguage struct {
Name string `xml:"name,attr"`
FilesCount int32 `xml:"files_count,attr"`
Code int32 `xml:"code,attr"`
Comments int32 `xml:"comment,attr"`
Blanks int32 `xml:"blank,attr"`
}

type Language struct {
name string
lineComments []string
Expand Down
39 changes: 34 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ func main() {

switch opts.OutputType {
case OutputTypeClocXml:
t := XMLTotal{
t := XMLTotalFiles{
Code: total.code,
Comment: total.comments,
Blank: total.blanks,
}
f := XMLResultFiles{
f := &XMLResultFiles{
Files: sortedFiles,
Total: t,
}
Expand Down Expand Up @@ -167,9 +167,38 @@ func main() {
}
sort.Sort(sortedLanguages)

for _, language := range sortedLanguages {
fmt.Printf("%-27v %6v %14v %14v %14v\n",
language.name, len(language.files), language.blanks, language.comments, language.code)
switch opts.OutputType {
case OutputTypeClocXml:
var langs []ClocLanguage
for _, language := range sortedLanguages {
c := ClocLanguage{
Name: language.name,
FilesCount: int32(len(language.files)),
Code: language.code,
Comments: language.comments,
Blanks: language.blanks,
}
langs = append(langs, c)
}
t := XMLTotalLanguages{
Code: total.code,
Comment: total.comments,
Blank: total.blanks,
SumFiles: total.total,
}
f := &XMLResultLanguages{
Languages: langs,
Total: t,
}
xmlResult := XMLResult{
XMLLanguages: f,
}
xmlResult.Encode()
default:
for _, language := range sortedLanguages {
fmt.Printf("%-27v %6v %14v %14v %14v\n",
language.name, len(language.files), language.blanks, language.comments, language.code)
}
}
}

Expand Down
23 changes: 18 additions & 5 deletions xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,31 @@ import (
"fmt"
)

type XMLTotal struct {
type XMLTotalLanguages struct {
SumFiles int32 `xml:"sum_files,attr"`
Code int32 `xml:"code,attr"`
Comment int32 `xml:"comment,attr"`
Blank int32 `xml:"blank,attr"`
}
type XMLResultLanguages struct {
Languages []ClocLanguage `xml:"language"`
Total XMLTotalLanguages `xml:"total"`
}

type XMLTotalFiles struct {
Code int32 `xml:"code,attr"`
Comment int32 `xml:"comment,attr"`
Blank int32 `xml:"blank,attr"`
}
type XMLResultFiles struct {
Files []ClocFile `xml:"file"`
Total XMLTotal `xml:"total"`
Files []ClocFile `xml:"file"`
Total XMLTotalFiles `xml:"total"`
}

type XMLResult struct {
XMLName xml.Name `xml:"results"`
XMLFiles XMLResultFiles `xml:"files"`
XMLName xml.Name `xml:"results"`
XMLFiles *XMLResultFiles `xml:"files,omitempty"`
XMLLanguages *XMLResultLanguages `xml:"languages,omitempty"`
}

func (x *XMLResult) Encode() {
Expand Down

0 comments on commit caee9f2

Please sign in to comment.