-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
47 lines (39 loc) · 776 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
package main
import (
"flag"
"fmt"
"io"
"os"
)
var msg = `
Usage: goodhangul FILENAME [OPTION]
A converter for hwp files
OPTIONS:
xml parse and output the file to xml
pdf parse and output the file to pdf
`
// bit of a hack. Stdandard flag lib doesn't allow flag.Parse(os.Args[2]). You need a subcommand to do so.
var optionCmd = flag.NewFlagSet("", flag.ExitOnError)
func main() {
//check if enough arguments were given
if len(os.Args) < 2 {
fmt.Println(msg)
os.Exit(1)
}
err := optionCmd.Parse(os.Args[0:])
if err != nil {
fmt.Println(msg)
os.Exit(1)
}
fileName := os.Args[1]
f, err := os.Open(fileName)
if err != nil {
fmt.Println(msg)
os.Exit(1)
}
err = Parse(f)
if err != nil && err != io.EOF {
fmt.Println(msg)
os.Exit(1)
}
}