mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-05-23 16:40:08 -03:00
Fixed output text
This commit is contained in:
parent
b2fe3f69ce
commit
bd402a063c
@ -47,7 +47,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if relativePath == "." {
|
if relativePath == "." {
|
||||||
return printFileAnalysis(root)
|
fmt.Print(printFileAnalysis(root))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
@ -87,6 +88,7 @@ func main() {
|
|||||||
out[language] = append(out[language], relativePath)
|
out[language] = append(out[language], relativePath)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -157,26 +159,26 @@ func printFileAnalysis(file string) string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
totalLines, linesOfCode := getLines(file, string(content))
|
|
||||||
|
totalLines, nonBlank := getLines(file, string(content))
|
||||||
fileType := getFileType(file, content)
|
fileType := getFileType(file, content)
|
||||||
language := enry.GetLanguage(file, content)
|
language := enry.GetLanguage(file, content)
|
||||||
mimeType := enry.GetMimeType(language)
|
mimeType := enry.GetMimeType(file, language)
|
||||||
|
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
`%s: %d lines (%d sloc)
|
`%s: %d lines (%d sloc)
|
||||||
type: %s
|
type: %s
|
||||||
mime_type: %s
|
mime_type: %s
|
||||||
language: %s
|
language: %s
|
||||||
`,
|
`,
|
||||||
filepath.Base(file), totalLines, linesOfCode, fileType, mimeType, language)
|
filepath.Base(file), totalLines, nonBlank, fileType, mimeType, language,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLines(file string, content string) (int, int) {
|
func getLines(file string, content string) (int, int) {
|
||||||
|
|
||||||
totalLines := strings.Count(content, "\n")
|
totalLines := strings.Count(content, "\n")
|
||||||
linesOfCode := totalLines - strings.Count(content, "\n\n")
|
nonBlank := totalLines - strings.Count(content, "\n\n")
|
||||||
|
return totalLines, nonBlank
|
||||||
return totalLines, linesOfCode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFileType(file string, content []byte) string {
|
func getFileType(file string, content []byte) string {
|
||||||
|
12
utils.go
12
utils.go
@ -53,20 +53,24 @@ func IsDocumentation(path string) bool {
|
|||||||
return data.DocumentationMatchers.Match(path)
|
return data.DocumentationMatchers.Match(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsImage(file string) bool {
|
func IsImage(path string) bool {
|
||||||
index := strings.LastIndex(file, ".")
|
extension := filepath.Ext(path)
|
||||||
extension := file[index:]
|
|
||||||
if extension == ".png" || extension == ".jpg" || extension == ".jpeg" || extension == ".gif" {
|
if extension == ".png" || extension == ".jpg" || extension == ".jpeg" || extension == ".gif" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMimeType(language string) string {
|
func GetMimeType(path string, language string) string {
|
||||||
if mime, ok := data.LanguagesMime[language]; ok {
|
if mime, ok := data.LanguagesMime[language]; ok {
|
||||||
return mime
|
return mime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if IsImage(path) {
|
||||||
|
return "image/" + filepath.Ext(path)[1:]
|
||||||
|
}
|
||||||
|
|
||||||
return "text/plain"
|
return "text/plain"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user