File: main.go

package info (click to toggle)
golang-github-gobwas-glob 0.2.3%2Bgit20180208.19c076c-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports
  • size: 364 kB
  • sloc: sh: 20; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 900 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main

import (
	"flag"
	"fmt"
	"github.com/gobwas/glob"
	"github.com/gobwas/glob/match"
	"github.com/gobwas/glob/match/debug"
	"os"
	"strings"
	"unicode/utf8"
)

func main() {
	pattern := flag.String("p", "", "pattern to draw")
	sep := flag.String("s", "", "comma separated list of separators characters")
	flag.Parse()

	if *pattern == "" {
		flag.Usage()
		os.Exit(1)
	}

	var separators []rune
	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)
			}
		}
	}

	glob, err := glob.Compile(*pattern, separators...)
	if err != nil {
		fmt.Println("could not compile pattern:", err)
		os.Exit(1)
	}

	matcher := glob.(match.Matcher)
	fmt.Fprint(os.Stdout, debug.Graphviz(*pattern, matcher))
}