...

Source file src/github.com/gobwas/glob/cmd/globdraw/main.go

Documentation: github.com/gobwas/glob/cmd/globdraw

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"github.com/gobwas/glob"
     7  	"github.com/gobwas/glob/match"
     8  	"github.com/gobwas/glob/match/debug"
     9  	"os"
    10  	"strings"
    11  	"unicode/utf8"
    12  )
    13  
    14  func main() {
    15  	pattern := flag.String("p", "", "pattern to draw")
    16  	sep := flag.String("s", "", "comma separated list of separators characters")
    17  	flag.Parse()
    18  
    19  	if *pattern == "" {
    20  		flag.Usage()
    21  		os.Exit(1)
    22  	}
    23  
    24  	var separators []rune
    25  	if len(*sep) > 0 {
    26  		for _, c := range strings.Split(*sep, ",") {
    27  			if r, w := utf8.DecodeRuneInString(c); len(c) > w {
    28  				fmt.Println("only single charactered separators are allowed")
    29  				os.Exit(1)
    30  			} else {
    31  				separators = append(separators, r)
    32  			}
    33  		}
    34  	}
    35  
    36  	glob, err := glob.Compile(*pattern, separators...)
    37  	if err != nil {
    38  		fmt.Println("could not compile pattern:", err)
    39  		os.Exit(1)
    40  	}
    41  
    42  	matcher := glob.(match.Matcher)
    43  	fmt.Fprint(os.Stdout, debug.Graphviz(*pattern, matcher))
    44  }
    45  

View as plain text