-
Notifications
You must be signed in to change notification settings - Fork 0
/
gobadger.go
45 lines (38 loc) · 908 Bytes
/
gobadger.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
package main
import (
"flag"
"fmt"
"os"
"github.com/narqo/go-badge"
)
func main() {
var outputFile, color, title, value string
flag.StringVar(&outputFile, "o", "badge.svg", "output file name")
flag.StringVar(&color, "c", "#5272B4", "color of badge")
flag.StringVar(&title, "t", "", "title")
flag.StringVar(&value, "v", "", "Value for the title")
flag.Parse()
if title == "" || value == "" {
fmt.Fprintln(os.Stderr, "title and value are required")
flag.Usage()
os.Exit(1)
}
err := generateBadge(outputFile, title, value, color)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}
func generateBadge(outputFile, title, value, color string) error {
f, err := os.Create(outputFile)
if err != nil {
return err
}
defer f.Close()
b, err := badge.RenderBytes(title, value, badge.Color(color))
if err != nil {
return err
}
_, err = f.Write(b)
return err
}