forked from alistanis/st
/
main.go
62 lines (53 loc) · 987 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
62
package main
import (
"flag"
"fmt"
"os"
"github.com/alistanis/st/flags"
"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 := flags.ParseFlags()
if err != nil {
fmt.Println(err)
usage()
return -1
}
options := &parse.Options{
Tag: flags.Tag,
Case: flags.Case,
AppendMode: flags.AppendMode,
TagMode: flags.TagMode,
// this is confusing, I'll fix it later when changing documentation/flags behavior
DryRun: !flags.Write,
Verbose: flags.Verbose}
parse.SetOptions(options)
err = parse.AndProcessFiles(flag.Args())
if err != nil {
fmt.Println(err)
return -1
}
return 0
}
func usage() {
fmt.Fprintf(os.Stderr, "usage: st [flags] [path ...]\n")
flag.PrintDefaults()
exit(-2)
}
func main() {
exit(run())
}