-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
59 lines (49 loc) · 1.26 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
58
59
//go:build !test
package main
import (
"flag"
"fmt"
"os"
)
func printVersion() {
fmt.Fprintln(os.Stderr, name)
fmt.Fprintf(os.Stderr, "Source: %s\n", source)
fmt.Fprintf(os.Stderr, "Version: %s\n", version)
fmt.Fprintf(os.Stderr, "Commit: %s\n", commit)
fmt.Fprintf(os.Stderr, "Platform: %s\n", platform)
fmt.Fprintf(os.Stderr, "Build Time: %s\n", buildTime)
}
func printUsage() {
printVersion()
fmt.Fprintln(os.Stderr, "usage:")
flag.PrintDefaults()
}
func main() {
_file := flag.String("file", "", "file or URL to the xml")
_f := flag.String("f", "", "file or URL to the xml")
_xpath := flag.String("xpath", "", "the xpath expression")
_x := flag.String("x", "", "the xpath expression")
_version := flag.Bool("version", false, "print the version")
_v := flag.Bool("v", false, "print the version")
_help := flag.Bool("help", false, "print usage")
_h := flag.Bool("h", false, "print usage")
flag.Parse()
if *_h || *_help {
printUsage()
os.Exit(0)
}
if *_v || *_version {
printVersion()
os.Exit(0)
}
file, xpath, err := parseArguments(*_file, *_f, *_xpath, *_x)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
printUsage()
os.Exit(1)
}
if err := xq(file, xpath); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
}