-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
61 lines (52 loc) · 948 Bytes
/
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
package main
import (
"flag"
"fmt"
"os"
"github.com/alistanis/st/parse"
)
var (
exitFunction = defaultExitFunc
)
func defaultExitFunc(code int) {
os.Exit(code)
}
func exit(code int) {
if exitFunction != nil {
exitFunction(code)
} else {
defaultExitFunc(code)
}
}
func run() int {
flag.Usage = usage
err := parse.Flags()
if err != nil {
fmt.Println(err)
usage()
return -1
}
options := &parse.Options{
Tag: parse.Tag,
Case: parse.Case,
AppendMode: parse.AppendMode,
TagMode: parse.TagMode,
// this is confusing, I'll fix it later when changing documentation/flags behavior
DryRun: !parse.Write,
Verbose: parse.Verbose}
parse.SetOptions(options)
err = parse.AndProcessFiles(flag.Args())
if err != nil {
fmt.Println(err)
return -1
}
return 0
}
func usage() {
fmt.Fprintln(os.Stderr, "usage: st [flags] [path ...]")
flag.PrintDefaults()
exit(-2)
}
func main() {
exit(run())
}