mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-05-23 08:30:07 -03:00
command improvements
This commit is contained in:
parent
947a0d3d44
commit
e0a990e4ea
@ -13,10 +13,19 @@ import (
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
root := flag.Arg(0)
|
||||
root, err := filepath.Abs(flag.Arg(0))
|
||||
ifError(err)
|
||||
|
||||
if root == "" {
|
||||
usage()
|
||||
}
|
||||
|
||||
o := make(map[string][]string, 0)
|
||||
filepath.Walk(root, func(path string, f os.FileInfo, err error) error {
|
||||
err = filepath.Walk(root, func(path string, f os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if slinguist.IsVendor(f.Name()) || slinguist.IsDotFile(f.Name()) {
|
||||
if f.IsDir() {
|
||||
return filepath.SkipDir
|
||||
@ -36,10 +45,30 @@ func main() {
|
||||
|
||||
}
|
||||
|
||||
o[l] = append(o[l], path)
|
||||
r, _ := filepath.Rel(root, path)
|
||||
o[l] = append(o[l], r)
|
||||
return nil
|
||||
})
|
||||
|
||||
ifError(err)
|
||||
|
||||
js, _ := json.MarshalIndent(o, "", " ")
|
||||
fmt.Printf("%s\n", js)
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(
|
||||
os.Stderr, "simple-linguist, A simple (and faster) implementation of linguist \nusage: %s <path>\n",
|
||||
os.Args[0],
|
||||
)
|
||||
|
||||
flag.PrintDefaults()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func ifError(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user