mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-05-23 16:40:08 -03:00
fix json output for a single file; fixes #159
Signed-off-by: Denys Smirnov <denys@sourced.tech>
This commit is contained in:
parent
15bb13117f
commit
03e4a029c2
@ -51,7 +51,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fileInfo.Mode().IsRegular() {
|
if fileInfo.Mode().IsRegular() {
|
||||||
err = printFileAnalysis(root, limit)
|
err = printFileAnalysis(root, limit, *jsonFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ func byteCountValues(files []string) (float64, filelistError) {
|
|||||||
return t, filesErr
|
return t, filesErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func printFileAnalysis(file string, limit int64) error {
|
func printFileAnalysis(file string, limit int64, isJSON bool) error {
|
||||||
data, err := readFile(file, limit)
|
data, err := readFile(file, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -280,6 +280,17 @@ func printFileAnalysis(file string, limit int64) error {
|
|||||||
language := enry.GetLanguage(file, data)
|
language := enry.GetLanguage(file, data)
|
||||||
mimeType := enry.GetMimeType(file, language)
|
mimeType := enry.GetMimeType(file, language)
|
||||||
|
|
||||||
|
if isJSON {
|
||||||
|
return json.NewEncoder(os.Stdout).Encode(map[string]interface{}{
|
||||||
|
"filename": filepath.Base(file),
|
||||||
|
"lines": nonBlank,
|
||||||
|
"total_lines": totalLines,
|
||||||
|
"type": fileType,
|
||||||
|
"mime": mimeType,
|
||||||
|
"language": language,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
`%s: %d lines (%d sloc)
|
`%s: %d lines (%d sloc)
|
||||||
type: %s
|
type: %s
|
||||||
|
Loading…
x
Reference in New Issue
Block a user