-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (33 loc) · 795 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
package main
import (
"flag"
"fmt"
"os"
"text/tabwriter"
"github.com/seruman/tureng-cli/tureng"
)
func main() {
fs := flag.NewFlagSet("tureng", flag.ExitOnError)
flagDebug := fs.Bool("debug", false, "enable debug mode to dump request/response")
err := fs.Parse(os.Args[1:])
if err != nil {
fs.PrintDefaults()
os.Exit(1)
}
args := fs.Args()
if len(args) < 1 || args[0] == "" {
fs.PrintDefaults()
os.Exit(1)
}
t := tureng.NewClient(tureng.WithDebug(*flagDebug))
results, err := t.Translate(args[0])
if err != nil {
os.Exit(1)
}
const padding = 3
w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, ' ', 0)
for _, v := range results {
fmt.Fprintf(w, "%s\t%s(%s)\t%s(%s)\n", v.CategoryTextB, v.TermA, v.TermTypeTextA, v.TermB, v.TermTypeTextB)
}
w.Flush()
}