glob/cmd/globdraw/main.go

45 lines
863 B
Go
Raw Normal View History

2016-01-22 19:16:46 +03:00
package main
import (
"flag"
"fmt"
"os"
"strings"
2016-02-02 22:03:37 +03:00
"unicode/utf8"
2018-02-16 17:36:02 +03:00
"github.com/gobwas/glob"
"github.com/gobwas/glob/match"
2016-01-22 19:16:46 +03:00
)
func main() {
pattern := flag.String("p", "", "pattern to draw")
2016-02-02 22:03:37 +03:00
sep := flag.String("s", "", "comma separated list of separators characters")
2016-01-22 19:16:46 +03:00
flag.Parse()
if *pattern == "" {
flag.Usage()
os.Exit(1)
}
2016-02-02 22:03:37 +03:00
var separators []rune
2016-02-24 20:23:24 +03:00
if len(*sep) > 0 {
for _, c := range strings.Split(*sep, ",") {
if r, w := utf8.DecodeRuneInString(c); len(c) > w {
fmt.Println("only single charactered separators are allowed")
os.Exit(1)
} else {
separators = append(separators, r)
}
2016-02-02 22:03:37 +03:00
}
}
glob, err := glob.Compile(*pattern, separators...)
2016-01-22 19:16:46 +03:00
if err != nil {
fmt.Println("could not compile pattern:", err)
os.Exit(1)
}
matcher := glob.(match.Matcher)
2018-02-16 17:36:02 +03:00
fmt.Fprint(os.Stdout, match.Graphviz(*pattern, matcher))
2016-01-22 19:16:46 +03:00
}