-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
78 lines (64 loc) · 1.5 KB
/
main.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"flag"
"fmt"
"os"
"github.com/tinychameleon/blocky/shape"
"github.com/tinychameleon/blocky/strategy"
"github.com/tinychameleon/blocky/svg"
)
type cmdFlags struct {
debug bool
keep bool
exclude string
strategy string
}
func main() {
var flags cmdFlags
flag.BoolVar(&flags.debug, "debug", false, "Enable debug mode")
flag.BoolVar(&flags.keep, "keepInvisible", false,
"Output elements that have 0x00 alpha values")
flag.StringVar(&flags.exclude, "exclude", "",
"Exclude #RRGGBB[AA] colour from output")
flag.StringVar(&flags.strategy, "optimize", "pixels",
"Optimize SVG rectangle output. Values: pixels")
flag.Usage = usage
flag.Parse()
options := fromFlags(flags)
s, err := svg.New(flag.Arg(0), options...)
if err != nil {
exit("Bad input file:", err)
}
fmt.Println(s)
}
func fromFlags(flags cmdFlags) []svg.Option {
var o []svg.Option
if flags.debug {
o = append(o, svg.DebugMode)
}
if flags.keep {
o = append(o, svg.KeepInvisible)
}
if flags.exclude != "" {
c, err := shape.ParseHex(flags.exclude)
if err != nil {
exit("Bad -exclude value:", err)
}
o = append(o, svg.Exclude(c))
}
f := strategy.Pixels
if flags.strategy == "rects" {
f = strategy.Rects
}
o = append(o, svg.Strategy(f))
return o
}
func exit(args ...interface{}) {
fmt.Fprintln(os.Stderr, args...)
os.Exit(1)
}
func usage() {
fmt.Printf("Usage: %s [-debug] [-keepInvisible] [-exclude=#RRGGBB[AA]] [-optimize=pixels|rects] FILE\n",
os.Args[0])
flag.PrintDefaults()
}