-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
46 lines (40 loc) · 927 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
// Package main is the entry point of the sqluv command.
package main
import (
"fmt"
"io"
"os"
"github.com/nao1215/sqluv/config"
"github.com/nao1215/sqluv/di"
)
// main is the entry point of the sqluv command.
func main() {
os.Exit(run(os.Stdout, os.Stderr, os.Args))
}
// run executes the sqluv command.
func run(stdout, stderr io.Writer, args []string) int {
arg, err := config.NewArgument(args)
if err != nil {
fmt.Fprintf(stderr, "failed to parse arguments: %v\n", err)
return 1
}
if arg.CanUsage() {
fmt.Fprintf(stdout, "%s", arg.Usage())
return 0
}
if arg.CanVersion() {
fmt.Fprintf(stdout, "%s", arg.Version())
return 0
}
sqluv, cleanup, err := di.NewSqluv(arg)
if err != nil {
fmt.Fprintf(stderr, "failed to initialize TUI: %v\n", err)
return 1
}
defer cleanup()
if err := sqluv.Run(); err != nil {
fmt.Fprintf(stderr, "failed to run TUI: %v\n", err)
return 1
}
return 0
}