-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (47 loc) · 1.06 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
package main
import (
"fmt"
"gbs2gb/constants"
"gbs2gb/gbs"
"gbs2gb/utils"
"github.com/jessevdk/go-flags"
"log"
"os"
"path"
"strings"
)
func main() {
opts := CommandLineOpts{}
parser := flags.NewParser(&opts, flags.Default)
_, err := parser.Parse()
if err != nil {
if w, ok := err.(*flags.Error); ok {
if w.Type == flags.ErrHelp {
return
}
log.Fatalln(err)
}
}
if opts.Version {
fmt.Printf("gbs2gb %s\n", constants.GitVersion)
return
}
if err := os.MkdirAll(opts.OutDir, 0750); err != nil {
log.Fatalf("Can't create output directory: %v", err)
}
_, inputBase := path.Split(opts.InputFile)
inputNoext := strings.TrimSuffix(inputBase, path.Ext(inputBase))
outputFile := path.Join(opts.OutDir, fmt.Sprintf("%s.gb", inputNoext))
log.Printf("→ %s", inputBase)
gbsBytes, err := utils.ReadAllBytes(opts.InputFile)
if err != nil {
log.Println(err)
return
}
err = gbs.MakeGB(gbsBytes, outputFile)
if err != nil {
log.Printf("Couldn't create GB file:")
log.Println(err)
}
log.Printf("Successfully created %s", outputFile)
}