tartrazine/cmd/slinguist/main.go

46 lines
748 B
Go
Raw Normal View History

2016-07-13 17:05:23 +00:00
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/src-d/simple-linguist"
)
func main() {
flag.Parse()
root := flag.Arg(0)
o := make(map[string][]string, 0)
filepath.Walk(root, func(path string, f os.FileInfo, err error) error {
if slinguist.IsVendor(f.Name()) || slinguist.IsDotFile(f.Name()) {
if f.IsDir() {
return filepath.SkipDir
}
return nil
}
if f.IsDir() {
return nil
}
l, safe := slinguist.GetLanguageByExtension(path)
if !safe {
content, _ := ioutil.ReadFile(path)
l, safe = slinguist.GetLanguageByContent(path, content)
}
o[l] = append(o[l], path)
return nil
})
js, _ := json.MarshalIndent(o, "", " ")
fmt.Printf("%s\n", js)
}