hhatto / gocloc

A little fast cloc(Count Lines Of Code)
MIT License
803 stars 81 forks source link

support output format options? #10

Closed hiroyukim closed 5 years ago

hiroyukim commented 6 years ago

I am using this library. I want to convert the output format to csv, tsv in order to link with other aggregation devices, but do you plan to support the output format option?

hhatto commented 6 years ago

It is not necessary as my own use case, there is no plan to add, now. I think that the json format is good if we add it in the future.

json format example:

{
    "version": 0.1,
    "result": [
        {
            "language": "Rust",
            "files": 23,
            "blank": 336,
            "comment": 258,
            "code": 4739
        },
        {
            "language": "D",
            "files": 294,
            "blank": 504,
            "comment": 0,
            "code": 2279
        },
        {
            "language": "JSON",
            "files": 273,
            "blank": 0,
            "comment": 0,
            "code": 273
        },
        {
            "language": "Markdown",
            "files": 1,
            "blank": 17,
            "comment": 0,
            "code": 43
        },
        {
            "language": "TOML",
            "files": 2,
            "blank": 5,
            "comment": 0,
            "code": 33
        },
        {
            "language": "YAML",
            "files": 1,
            "blank": 3,
            "comment": 0,
            "code": 12
        }
    ]
}

Pull Requests are always welcome 😄

Thanks.

hiroyukim commented 6 years ago

@hhatto

Thanks for the reply. Let's examine json's options.

alexellis commented 5 years ago

I'd like to use this tool with JSON format. I saw it'd not been implemented yet. I assume since there is XML format, that JSON would be easy for the maintainers to add. What are your thoughts?

Alex

alexellis commented 5 years ago

It'd also be nice to have the total as well as the breakdowns.

hhatto commented 5 years ago

@hiroyukim @alexellis

support json output format in latest master, and release v0.2.1.

files output:

$ gocloc --output-type json . | jq "."
{
  "languages": [
    {
      "name": "Go",
      "files": 14,
      "code": 1466,
      "comment": 47,
      "blank": 182
    },
    {
      "name": "Markdown",
      "files": 1,
      "code": 149,
      "comment": 0,
      "blank": 20
    },
        :
    {
      "name": "TOML",
      "files": 1,
      "code": 9,
      "comment": 0,
      "blank": 2
    }
  ],
  "total": {
    "files": 20,
    "code": 1783,
    "comment": 50,
    "blank": 213
  }
}

with --by-file option:

gocloc --output-type json --by-file . | jq "."
{
  "files": [
    {
      "code": 522,
      "comment": 5,
      "blank": 26,
      "name": "language.go",
      "Lang": "Go"
    },
        :
    {
      "code": 183,
      "comment": 12,
      "blank": 25,
      "name": "cmd/gocloc/main.go",
      "Lang": "Go"
    },
    {
      "code": 7,
      "comment": 16,
      "blank": 5,
      "name": "utils_test.go",
      "Lang": "Go"
    }
  ],
  "total": {
    "files": 20,
    "code": 1783,
    "comment": 50,
    "blank": 213
  }
}

Please feedback 😄 Thanks