-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
executable file
·55 lines (47 loc) · 1.63 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
package main
import (
"github.com/jochenboesmans/gedcom-parser/grpc"
"github.com/jochenboesmans/gedcom-parser/parse"
"github.com/joho/godotenv"
"log"
"os"
)
func init() {
if err := godotenv.Load(); err != nil {
log.Println("No .env file found. Some functionality might not work if you don't supply environment variables.")
}
}
func main() {
checkMainArg()
switch os.Args[1] {
case "parse":
checkFilepathArgs()
parse.Parse(os.Args[2], os.Args[3])
case "serve":
grpc.Serve()
case "help":
helpMessage := `
Usage: 'gedcom-parser <command> <inputFilePath> <outputFilePath>'
* <command> [REQUIRED]:
parse - Parse local files. Requires the inputFilePath and outputFilePath to be specified.
serve - Start a gRPC server for gedcom parsing on remote file storage.
* <inputFilePath> [OPTIONAL]:
Relative path to the input file to parse. Please make sure to use the file extensions .ged, .json and .protobuf for respectively GEDCOM, JSON and Protobuf files.
* <outputFilePath> [OPTIONAL]:
Relative path to the output file. Please make sure to use the file extensions .ged, .json and .protobuf for respectively GEDCOM, JSON and Protobuf files.
`
log.Fatal(helpMessage)
default:
log.Fatalln("please choose a valid command (use 'gedcom-parser help' for more information on usage)")
}
}
func checkMainArg() {
if len(os.Args) < 2 {
log.Fatalln("please choose a command (use 'gedcom-parser help' for more information on usage)")
}
}
func checkFilepathArgs() {
if len(os.Args) < 4 {
log.Fatalln("please supply inputFilePath and outputFilePath respectively (use 'gedcom-parser help' for more information on usage)")
}
}