-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (60 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
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/sascha-andres/reuse/flag"
"github.com/sascha-andres/git-cl/internal"
)
var (
version, configFile string
help, printConfig bool
)
// main you know
func main() {
flag.Parse()
if help {
flag.Usage()
os.Exit(0)
}
options := make([]internal.ChangeLogGeneratorOption, 0)
if printConfig {
options = append(options, internal.WithPrintConfiguration())
}
if !printConfig && version != "" {
options = append(options, internal.WithVersion(version))
}
if !printConfig && configFile != "" {
data, err := os.ReadFile(configFile)
if err != nil {
_, _ = fmt.Fprint(os.Stderr, fmt.Sprintf("error reading configuration file: %s", err))
os.Exit(1)
}
var c internal.ChangeLogGenerator
err = json.Unmarshal(data, &c)
if err != nil {
_, _ = fmt.Fprint(os.Stderr, fmt.Sprintf("error parsing configuration: %s", err))
os.Exit(1)
}
options = append(options, internal.WithConfiguration(&c))
}
clg, err := internal.NewChangeLogGenerator(os.Stdin, options...)
if err != nil {
os.Exit(1)
}
var result string
result, err = clg.Build()
if err != nil {
fmt.Printf("error: %s", err)
os.Exit(1)
}
if result != "" {
fmt.Println(result)
}
}
func init() {
flag.BoolVar(&help, "help", false, "show help")
flag.StringVar(&version, "version", "", "provide version")
flag.StringVar(&configFile, "config-file", "", "provide path to config file")
flag.BoolVar(&printConfig, "print-config", false, "pass to print used config")
}