-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (46 loc) · 1.09 KB
/
main.go
File metadata and controls
49 lines (46 loc) · 1.09 KB
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
package main
import (
"encoding/json"
"encoding/xml"
"flag"
"fmt"
"os"
"github.com/indexdata/cql-go/cql"
)
func main() {
var outFmt string
var strict bool
flag.StringVar(&outFmt, "t", "cql", "output format: cql, json, struct, xml, xcql")
flag.BoolVar(&strict, "s", false, "strict CQL, e.g no multi-terms (default false)")
flag.Parse()
var p cql.Parser
for _, arg := range flag.Args() {
p.Strict = strict
query, err := p.Parse(arg)
if err != nil {
fmt.Fprintln(os.Stderr, "ERROR", err)
os.Exit(1)
}
switch outFmt {
case "cql":
fmt.Println(&query)
case "json":
out, _ := json.MarshalIndent(&query, "", " ")
fmt.Printf("%s\n", out)
case "xml":
out, _ := xml.MarshalIndent(&query, "", " ")
fmt.Printf("%s\n", out)
case "struct":
fmt.Printf("%+v\n", query)
case "xcql":
os.Stdout.WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
err := (&cql.Xcql{}).Write(query, 2, os.Stdout)
if err != nil {
fmt.Fprintln(os.Stderr, "ERROR", err)
}
default:
fmt.Fprintln(os.Stderr, "Unknown output format:", outFmt)
os.Exit(1)
}
}
}