mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-05-23 08:30:07 -03:00
basic command
This commit is contained in:
parent
6bc52531e7
commit
180da1c6df
45
cmd/slinguist/main.go
Normal file
45
cmd/slinguist/main.go
Normal file
@ -0,0 +1,45 @@
|
||||
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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user